Authenticating with a Token
> nats-server --auth mytokenConnecting with a Token
// Set a token
nc, err := nats.Connect("127.0.0.1", nats.Name("API Token Example"), nats.Token("mytoken"))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connectionOptions options = new Options.Builder().
server("nats://localhost:4222").
token("mytoken"). // Set a token
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();let nc = NATS.connect({url: `nats://127.0.0.1:${port}`, token: "mytoken!"});nc = NATS()
await nc.connect(servers=["nats://demo.nats.io:4222"], token="mytoken")
# Do something with the connection.Connecting with a Token in the URL
最后更新于