I’m aware of the automatic connection and topology recovery. However, I’m implementing a connection to third-party API and the documentation states, in several places, that RMQ Client automatic recovery should not be used.
I attach a ConnectionShutdownHandler:
public class ThirdPartyConnection
...
_connection.ConnectionShutdown += ConnectionShutdownHandler;
...
void ConnectionShutdownHandler(object source, ShutdownEventArgs args)
{
var connection = (IConnection)source;
if (args.ReplyCode == 200)
{
_logger.Information($"Connection shutdown [{args.ReplyCode}]: {args.ReplyText}. {string.Join(",", connection.ShutdownReport)}");
}
else
{
_logger.Error(args.Exception, $"Connection terminated [{args.ReplyCode}]: {args.ReplyText}. {string.Join(",", connection.ShutdownReport)}");
}
}
}
Calling Dispose
on the connection, when ReplyCode is not 200, blocks. I guess it makes sense, as I’m inside the event handler, so disposing of the instance that raised the event doesn’t make sense.
https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/154 suggests, there is no need to clean up as Connection releases all the resources on error.
How can I dispose of the connection and the model when the connection shuts down?