Set the Number of Reconnect Attempts
// 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 connectionOptions 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();const nc = await connect({
maxReconnectAttempts: 10,
servers: ["demo.nats.io"],
});Last updated
Was this helpful?