1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00
nats.docs/_examples/no_echo.html
Stephen Asbury 57db99feba Cleaned up how examples are handled to reduce thrashing in git
Examples are no longer in the final html as solo files, only in their container file
2019-05-15 10:41:36 -07:00

106 lines
4.8 KiB
HTML

<div class="tab-wrap">
<input type="radio" id="no_echo_go" name="no_echo" class="tab" checked>
<label for="no_echo_go" class="api-lang" data-language="go">Go</label>
<input type="radio" id="no_echo_java" name="no_echo" class="tab">
<label for="no_echo_java" class="api-lang" data-language="java">Java</label>
<input type="radio" id="no_echo_js" name="no_echo" class="tab">
<label for="no_echo_js" class="api-lang" data-language="js">JavaScript</label>
<input type="radio" id="no_echo_py" name="no_echo" class="tab">
<label for="no_echo_py" class="api-lang" data-language="py">Python</label>
<input type="radio" id="no_echo_ruby" name="no_echo" class="tab">
<label for="no_echo_ruby" class="api-lang" data-language="ruby">Ruby</label>
<input type="radio" id="no_echo_ts" name="no_echo" class="tab">
<label for="no_echo_ts" class="api-lang" data-language="ts">TypeScript</label>
<div class="tab__content">
<pre id="no_echo_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/no_echo/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Turn off echo
nc, err := nats.Connect(&#34;demo.nats.io&#34;, nats.NoEcho())
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connection
</code></pre>
</div>
<div class="tab__content">
<pre id="no_echo_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectNoEcho.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
server(&#34;nats://demo.nats.io:4222&#34;).
noEcho(). // Turn off echo
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();
</code></pre>
</div>
<div class="tab__content">
<pre id="no_echo_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L239-241"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// no_echo is not supported.
</code></pre>
</div>
<div class="tab__content">
<pre id="no_echo_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/no_echo.py#L5-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">ncA = NATS()
ncB = NATS()
await ncA.connect(no_echo=True)
await ncB.connect()
async def handler(msg):
# Messages sent by `ncA&#39; will not be received.
print(&#34;[Received] &#34;, msg)
await ncA.subscribe(&#34;greetings&#34;, cb=handler)
await ncA.flush()
await ncA.publish(&#34;greetings&#34;, b&#39;Hello World!&#39;)
await ncB.publish(&#34;greetings&#34;, b&#39;Hello World!&#39;)
# Do something with the connection
await asyncio.sleep(1)
await ncA.drain()
await ncB.drain()
</code></pre>
</div>
<div class="tab__content">
<pre id="no_echo_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/no_echo.rb#L3-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start(&#34;nats://demo.nats.io:4222&#34;, no_echo: true) do |nc|
# ...
end
</code></pre>
</div>
<div class="tab__content">
<pre id="no_echo_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L222-225"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
url: &#34;nats://demo.nats.io:4222&#34;, noEcho: true});
</code></pre>
</div>
</div>