Connection Name
Connections can be assigned a name which will appear in some of the server monitoring data. This name is not required, but is highly recommended as a friendly connection name will help in monitoring, error reporting, debugging, and testing.
Go
Java
JavaScript
Python
Ruby
C
1
nc, err := nats.Connect("demo.nats.io", nats.Name("API Name Option Example"))
2
if err != nil {
3
log.Fatal(err)
4
}
5
defer nc.Close()
6
7
// Do something with the connection
Copied!
1
Options options = new Options.Builder().
2
server("nats://demo.nats.io:4222").
3
connectionName("API Name Option Example"). // Set Name
4
build();
5
Connection nc = Nats.connect(options);
6
7
// Do something with the connection
8
9
nc.close();
Copied!
1
const nc = await connect({
2
name: "my-connection",
3
servers: ["demo.nats.io:4222"],
4
});
Copied!
1
nc = NATS()
2
await nc.connect(
3
servers=["nats://demo.nats.io:4222"],
4
name="API Name Option Example")
5
6
# Do something with the connection
7
8
await nc.close()
Copied!
1
require 'nats/client'
2
3
NATS.start(servers: ["nats://demo.nats.io:4222"], name: "API Name Option Example") do |nc|
4
# Do something with the connection
5
6
# Close the connection
7
nc.close
8
end
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_SetName(opts, "API Name Option Example");
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!
Export as PDF
Copy link
Edit on GitHub