notes from a passionate developer





This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

MyNatsClient, new feature AutoReconnectOnFailure

NATS is designed to be always on and to guard the server/broker from misbehaving clients. So if your client somehow manages to send something that makes the message corrupt, the server will disconnect you. With the release of v0.6.0 of MyNatsClient, you now have the option to configure AutoReconnectOnFailure. So if the client gets to know that it has been disconnected due to a failure, it can be configured to try and reconnect. This can also be a failure caused by any of your subscribed observers causing an unhandled exception to be thrown.

AutoRecconectOnFailure (opt-in)

The default value for ConnectionInfo.AutoReconnectOnFailure is false so you have to explicitly opt-in to this feature. This is done to try and honour the "guard the server from misbehaving clients" design decision.

var connectionInfo = new ConnectionInfo(new Host(""))
    AutoReconnectOnFailure = true

using (var client = new NatsClient("myClientId", connectionInfo))
    //...Setup client...

    //If the client can NOT autoreconnect it will dispatch this event
    client.Events.OfType<ClientAutoReconnectFailed>().Subscribe(ev =>
        //Maybe manually try and connect again or something

    //...Use client...

That's it. Small release. Ant there's really nothing else for v0.6.0. Next feature will be convenience methods for Request-Response message pattern.


View Comments