 title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require &#39;nats/client&#39;

NATS.start(servers: [&#34;nats://127.0.0.1:1222&#34;, &#34;nats://127.0.0.1:1223&#34;, &#34;nats://127.0.0.1:1224&#34;]) do |nc|
   # Do something with the connection
   nc.on_reconnect do
    puts &#34;Got reconnected to #{nc.connected_server}&#34;
  end

  nc.on_disconnect do |reason|
    puts &#34;Got disconnected! #{reason}&#34;
  end
end
</code></pre>
	</div>
	
	<div cl