Set the Number of Reconnect Attempts
{% tabs %} {% tab title=”Go” %}
{% endtab %}
{% tab title=”Java” %}
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();
{% tab title=”JavaScript” %}
{% endtab %}
{% tab title=”Python” %}
nc = NATS()
max_reconnect_attempts=10,
)
# Do something with the connection
await nc.close()
{% tab title=”Ruby” %}
{% endtab %}
{% tab title=”C” %}
natsConnection *conn = NULL;
natsOptions *opts = NULL;
natsStatus s = NATS_OK;
if (s == NATS_OK)
s = natsOptions_SetMaxReconnect(opts, 10);
if (s == NATS_OK)
s = natsConnection_Connect(&conn, opts);
(...)
// Destroy objects that were created
natsConnection_Destroy(conn);