mirror of
				https://github.com/taigrr/nats.docs
				synced 2025-01-18 04:03:23 -08:00 
			
		
		
		
	
		
			
				
	
	
		
			107 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| 
 | |
| <div class="tab-wrap">
 | |
|   	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_go" name="reconnect_10s" class="tab" checked>
 | |
| 	
 | |
| 	<label for="reconnect_10s_go" class="api-lang" data-language="go">Go</label>
 | |
| 	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_java" name="reconnect_10s" class="tab">
 | |
| 	
 | |
| 	<label for="reconnect_10s_java" class="api-lang" data-language="java">Java</label>
 | |
| 	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_js" name="reconnect_10s" class="tab">
 | |
| 	
 | |
| 	<label for="reconnect_10s_js" class="api-lang" data-language="js">JavaScript</label>
 | |
| 	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_py" name="reconnect_10s" class="tab">
 | |
| 	
 | |
| 	<label for="reconnect_10s_py" class="api-lang" data-language="py">Python</label>
 | |
| 	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_ruby" name="reconnect_10s" class="tab">
 | |
| 	
 | |
| 	<label for="reconnect_10s_ruby" class="api-lang" data-language="ruby">Ruby</label>
 | |
| 	
 | |
| 	
 | |
| 	<input type="radio" id="reconnect_10s_ts" name="reconnect_10s" class="tab">
 | |
| 	
 | |
| 	<label for="reconnect_10s_ts" class="api-lang" data-language="ts">TypeScript</label>
 | |
| 	
 | |
| 
 | |
|   	
 | |
| 	<div class="tab__content">
 | |
| 	<pre id="reconnect_10s_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_10s/main.go#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-go">// Set reconnect interval to 10 seconds
 | |
| nc, err := nats.Connect("demo.nats.io", nats.ReconnectWait(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="reconnect_10s_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/ReconnectTenSeconds.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("nats://demo.nats.io:4222").
 | |
|                             reconnectWait(Duration.ofSeconds(10)).  // Set Reconnect Wait
 | |
|                             build();
 | |
| Connection nc = Nats.connect(options);
 | |
| 
 | |
| // Do something with the connection
 | |
| 
 | |
| nc.close();
 | |
| </code></pre>
 | |
| 	</div>
 | |
| 	
 | |
| 	<div class="tab__content">
 | |
| 	<pre id="reconnect_10s_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L42-47"><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 = NATS.connect({
 | |
|     reconnectTimeWait: 10 * 1000, //10s
 | |
|     servers: ["nats://demo.nats.io:4222"]
 | |
| });
 | |
| </code></pre>
 | |
| 	</div>
 | |
| 	
 | |
| 	<div class="tab__content">
 | |
| 	<pre id="reconnect_10s_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_10s.py#L5-16"><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(
 | |
|    servers=["nats://demo.nats.io:4222"],
 | |
|    reconnect_time_wait=10,
 | |
|    )
 | |
| 
 | |
| # Do something with the connection
 | |
| 
 | |
| await nc.close()
 | |
| 
 | |
| </code></pre>
 | |
| 	</div>
 | |
| 	
 | |
| 	<div class="tab__content">
 | |
| 	<pre id="reconnect_10s_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_10s.rb#L1-10"><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">require 'nats/client'
 | |
| 
 | |
| NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], reconnect_time_wait: 10) do |nc|
 | |
|    # Do something with the connection
 | |
| 
 | |
|    # Close the connection
 | |
|    nc.close
 | |
| end
 | |
| </code></pre>
 | |
| 	</div>
 | |
| 	
 | |
| 	<div class="tab__content">
 | |
| 	<pre id="reconnect_10s_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L33-40"><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">// will throw an exception if connection fails
 | |
| let nc = await connect({
 | |
|     reconnectTimeWait: 10*1000, //10s
 | |
|     servers: ["nats://demo.nats.io:4222"]
 | |
| });
 | |
| nc.close();
 | |
| </code></pre>
 | |
| 	</div>
 | |
| 	
 | |
| </div>
 |