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("192.168.1.176"))
{
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
ev.Client.Connect();
});
//...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.
//Daniel