Closed MrShiny608 closed 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);
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.
That client has since been superseded. Unfortunately, the new client doesn't work with nats-streaming-server. Instead you should be looking at JetStream
The Connect Options section of the readme states
I am trying to connect to a STAN cluster in a docker machine, at first I attempted the
url
form;which Node.JS internals did not like, so I attempted to use the
servers
parameter;At this point I hit lots of issues with timeouts, eventually I found that the
url
parameter was defaulting tolocalhost: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