Connecting to a Specific Server

The NATS client libraries can take a full URL, nats://, to specify a specific server host and port to connect to.

Libraries are removing the requirement for an explicit protocol and may allow or just In the later example the default port 4222 will be used. Check with your specific client library's documentation to see what URL formats are supported.

For example, to connect to the demo server with a URL you can use:

// If connecting to the default port, the URL can be simplified
// to just the hostname/IP.
// That is, the connect below is equivalent to:
// nats.Connect("nats://")
nc, err := nats.Connect("")
if err != nil {
defer nc.Close()

// Do something with the connection nc = Nats.connect("nats://");

Last updated