// Set max reconnects attempts
nc, err := nats.Connect("demo.nats.io", nats.MaxReconnects(10))
if err != nil {
	log.Fatal(err)
}
defer nc.Close()

// Do something with the connection

Options options = new Options.Builder().
                            server("nats://demo.nats.io:4222").
                            maxReconnects(10). // Set max reconnect attempts
                            build();
Connection nc = Nats.connect(options);

// Do something with the connection

nc.close();
let nc = NATS.connect({
    maxReconnectAttempts: 10,
    servers: ["nats://demo.nats.io:4222"]
});
nc = NATS()
await nc.connect(
   servers=["nats://demo.nats.io:4222"],
   max_reconnect_attempts=10,
   )

# Do something with the connection

await nc.close()

require 'nats/client'

NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], max_reconnect_attempts: 10) do |nc|
   # Do something with the connection

   # Close the connection
   nc.close
end
// will throw an exception if connection fails
let nc = await connect({
    maxReconnectAttempts: 10,
    servers: ["nats://demo.nats.io:4222"]
});
nc.close();