Set the Number of Reconnect Attempts

    {% tabs %} {% tab title=”Go” %}

    {% endtab %}

    {% tab title=”Java” %}

    1. server("nats://demo.nats.io:4222").
    2. maxReconnects(10). // Set max reconnect attempts
    3. build();
    4. Connection nc = Nats.connect(options);
    5. // Do something with the connection
    6. nc.close();

    {% tab title=”JavaScript” %}

    {% endtab %}

    {% tab title=”Python” %}

    1. nc = NATS()
    2. max_reconnect_attempts=10,
    3. )
    4. # Do something with the connection
    5. await nc.close()

    {% tab title=”Ruby” %}

    {% endtab %}

    {% tab title=”C” %}

    1. natsConnection *conn = NULL;
    2. natsOptions *opts = NULL;
    3. natsStatus s = NATS_OK;
    4. if (s == NATS_OK)
    5. s = natsOptions_SetMaxReconnect(opts, 10);
    6. if (s == NATS_OK)
    7. s = natsConnection_Connect(&conn, opts);
    8. (...)
    9. // Destroy objects that were created
    10. natsConnection_Destroy(conn);