Avoiding the Thundering Herd
However, if you want to disable the randomization process for connect and reconnect, so that servers are always checked in the same order, you can do that in most libraries with a connection option:
{% tabs %} {% tab title=”Go” %}
{% endtab %}
server("nats://demo.nats.io:4222").
noRandomize(). // Disable reconnect shuffle
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();
{% endtab %}
{% tab title=”JavaScript” %}
{% endtab %}
nc = NATS()
await nc.connect(
servers=[
"nats://demo.nats.io:1224"
],
dont_randomize=True,
)
# Do something with the connection
await nc.close()
{% endtab %}
{% tab title=”Ruby” %}
{% endtab %}
natsConnection *conn = NULL;
natsOptions *opts = NULL;
natsStatus s = NATS_OK;
s = natsOptions_Create(&opts);
if (s == NATS_OK)
s = natsOptions_SetServers(opts, servers, 3);
if (s == NATS_OK)
s = natsOptions_SetNoRandomize(opts, true);
if (s == NATS_OK)
s = natsConnection_Connect(&conn, opts);
(...)
// Destroy objects that were created
{% endtab %} {% endtabs %}