Connecting to the Default Server
Some libraries also provide a special way to connect to a default url, which is generally nats://localhost:4222:
nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// Do something with the connectionConnection nc = Nats.connect();
// Do something with the connection
nc.close();let nc = NATS.connect();
nc.on('connect', (c) => {
// Do something with the connection
doSomething();
// When done close it
nc.close();
});
nc.on('error', (err) => {
failed(err);
});最后更新于
这有帮助吗?