1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00
nats.docs/_examples/connect_options.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

103 lines
4.9 KiB
HTML

<div class="tab-wrap">
<input type="radio" id="connect_options_go" name="connect_options" class="tab" checked>
<label for="connect_options_go" class="api-lang" data-language="go">Go</label>
<input type="radio" id="connect_options_java" name="connect_options" class="tab">
<label for="connect_options_java" class="api-lang" data-language="java">Java</label>
<input type="radio" id="connect_options_js" name="connect_options" class="tab">
<label for="connect_options_js" class="api-lang" data-language="js">JavaScript</label>
<input type="radio" id="connect_options_py" name="connect_options" class="tab">
<label for="connect_options_py" class="api-lang" data-language="py">Python</label>
<input type="radio" id="connect_options_ruby" name="connect_options" class="tab">
<label for="connect_options_ruby" class="api-lang" data-language="ruby">Ruby</label>
<input type="radio" id="connect_options_ts" name="connect_options" class="tab">
<label for="connect_options_ts" class="api-lang" data-language="ts">TypeScript</label>
<div class="tab__content">
<pre id="connect_options_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_options/main.go#L11-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">nc, err := nats.Connect(nats.DefaultURL, nats.Timeout(10*time.Second))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connection
</code></pre>
</div>
<div class="tab__content">
<pre id="connect_options_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/ConnectWithOptions.java#L13-23"><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;).
connectionTimeout(Duration.ofSeconds(10)). // Set timeout
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();
</code></pre>
</div>
<div class="tab__content">
<pre id="connect_options_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L121-123"><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">// connection timeout is not supported on node-nats
</code></pre>
</div>
<div class="tab__content">
<pre id="connect_options_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_options.py#L5-13"><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">nc = NATS()
await nc.connect(connect_timeout=2)
# Do something with the connection
await nc.close()
</code></pre>
</div>
<div class="tab__content">
<pre id="connect_options_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_options.rb#L1-14"><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"># There is currently no connect timeout as part of the Ruby NATS client API, but you can use a timer to mimic it.
require &#39;nats/client&#39;
timer = EM.add_timer(5) do
NATS.connect do |nc|
# Do something with the connection
# Close the connection
nc.close
end
end
EM.cancel_timer(timer)
</code></pre>
</div>
<div class="tab__content">
<pre id="connect_options_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L89-95"><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;,
timeout: 1000
});
</code></pre>
</div>
</div>