nats-io / nats.net.v1

The official C# Client for NATS
Apache License 2.0
646 stars 151 forks source link

Cannot stop ConnectionFactory from creating a connection when reconnectOnConnect = true #861

Closed ava-romo closed 4 months ago

ava-romo commented 9 months ago

Proposed change

I would like to provide a cancellation token, or a method on the ConnectionFactory object that I can call to have it stop trying to create a connection. When reconnectOnConnect = true, then the ConnectionFactory.CreateConnection will block until it creates the connection, which is fine, but I don't have a way of stopping it. It'd be really great if it was async, too.

Use case

I want to be able to have the NATS client run before the server may be available. But then if the user wants to stop the client, and perhaps change config, then I want to be able to stop and re-start the ConnectionFactory.CreateConnection method

Contribution

No response

scottf commented 9 months ago

The best thing to do is use the connection listeners and handle it on your own, without using the reconnectOnConnect