nats-io / stan.js

Node.js client for NATS Streaming
Apache License 2.0
293 stars 49 forks source link

servers option is not honoured #197

Closed MrShiny608 closed 3 years ago

MrShiny608 commented 3 years ago

The Connect Options section of the readme states

"The stan.js client honors all standard nats.js connection options, with the exception of: - json - noEcho - preserveBuffers"

I am trying to connect to a STAN cluster in a docker machine, at first I attempted the url form;

      url: "nats://stan-1:4222,nats://stan-2:4222,nats://stan-3:4222",

which Node.JS internals did not like, so I attempted to use the servers parameter;

      servers: [
        "stan-1:4222",
        "stan-2:4222",
        "stan-3:4222",
      ],

At this point I hit lots of issues with timeouts, eventually I found that the url parameter was defaulting to localhost:4222, which from the context of my container, there was no response.

The only way I've managed to get around this is to specify a url from the list, but my concern here is that if that instance is down, then my client cannot connect to one of the working instances to then perform discovery.

I attempted commenting out the default, and everything worked as expected

mujtabashamas commented 3 years ago

I was having the same issue, it seems the timeout issues was due to incorrect cluster id being provided, the cluster id needs to be same as set up in the nats server, you can check that here. http://STAN_SERVER_IP:8222/streaming/serverz

Working for me

const SERVER = { servers: ['nats://token@primary:4222', 'nats://token@secondary:4222'], }

const stan = STAN.connect(CLUSTER_ID, CLIENT_ID, SERVER);

aricart commented 3 years ago

Depending on the version of the underlying nats client is it is possible that if you don't specify url, it will insert the localhost:4222 entry. The bypass you are doing is correct - you simply make your servers list, and provide one of the entries at the URL, the duplicate should be OK.

aricart commented 3 years ago

That client has since been superseded. Unfortunately, the new client doesn't work with nats-streaming-server. Instead you should be looking at JetStream