nats-io / nats-pure.rb

Ruby client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
129 stars 30 forks source link

updating the server list #9

Open ripienaar opened 7 years ago

ripienaar commented 7 years ago

When there are long running NATS clients you might have the environment change underneath you, like say perhaps the client is fed with data from SRV records or some other non DNS based service discovery method like consul, etcd or whatever

The retry logic of this client is great because I can tell it to retry infinitely and it will deal with complexities of resubscribing on reconnect etc, so I like infinite retries

Problem is once I kick the client off with such an infinite retry setting I never have an option to update the server list it should use on subsequent retries.

Now I could adjust the Client#server_pool from my side but at present of course there is no concurrency mutexes or anything like that around that array so it would be a terrible idea.

The NATS server publishing feature is nice on paper but in reality I find it not that useful, it publishes private IPs that arent reachable from outside NAT etcetc so there's some issues still and anyway sysadmins like to manage their connection pools more explicitly I found

Do you have thoughts on how we might handle this situation? A way to update the Client#server_pool that's safe while having infinite retries set on the client gem would be great but open to other approaches you can think of.

ripienaar commented 7 years ago

@wallyqs any ideas on this one?

wallyqs commented 7 years ago

Hi @ripienaar thought about this and even though other clients do not have this API, think that having an API which adds servers to the pool could be a good addition considering this use case, so could take a look at implementing, thanks for the feedback.

wallyqs commented 7 years ago

Hi @ripienaar also thanks for the wait on this one.. I have branch → https://github.com/nats-io/pure-ruby-nats/pull/18 where I refactored things a bit and would allow to include new servers into the pool via calling nats.update_server_pool("nats://127.0.0.1:8282") for example.

Let me know if this works for you and I'll prepare a release soon. Cheers!