Powered By GitBook
Disabling Reconnect
You can disable automatic reconnect with connection options:
Go
Java
JavaScript
Python
Ruby
TypeScript
C
1
// Disable reconnect attempts
2
nc, err := nats.Connect("demo.nats.io", nats.NoReconnect())
3
if err != nil {
4
log.Fatal(err)
5
}
6
defer nc.Close()
7
8
// Do something with the connection
Copied!
1
Options options = new Options.Builder().
2
server("nats://demo.nats.io:4222").
3
noReconnect(). // Disable reconnect attempts
4
build();
5
Connection nc = Nats.connect(options);
6
7
// Do something with the connection
8
9
nc.close();
Copied!
1
let nc = NATS.connect({
2
reconnect: false,
3
servers: ["nats://demo.nats.io:4222"]
4
});
Copied!
1
nc = NATS()
2
await nc.connect(
3
servers=[
4
"nats://demo.nats.io:1222",
5
"nats://demo.nats.io:1223",
6
"nats://demo.nats.io:1224"
7
],
8
allow_reconnect=False,
9
)
10
11
# Do something with the connection
12
13
await nc.close()
Copied!
1
require 'nats/client'
2
3
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], reconnect: false) do |nc|
4
# Do something with the connection
5
6
# Close the connection
7
nc.close
8
end
Copied!
1
// will throw an exception if connection fails
2
let nc = await connect({
3
reconnect: false,
4
servers: ["nats://demo.nats.io:4222"]
5
});
6
nc.close();
Copied!
1
natsConnection *conn = NULL;
2
natsOptions *opts = NULL;
3
natsStatus s = NATS_OK;
4
5
s = natsOptions_Create(&opts);
6
if (s == NATS_OK)
7
s = natsOptions_SetAllowReconnect(opts, false);
8
if (s == NATS_OK)
9
s = natsConnection_Connect(&conn, opts);
10
11
(...)
12
13
// Destroy objects that were created
14
natsConnection_Destroy(conn);
15
natsOptions_Destroy(opts);
Copied!
Last modified 10mo ago
Export as PDF
Copy link