I am using RabbitMQ 3.6.0 with MasstTransit 3.2.0 and configure it as following:
// MassTransit
IBusControl bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri(configuration.Url), h =>
{
h.Username(configuration.User.UserName);
h.Password(configuration.User.Password);
});
cfg.UseXmlSerializer();
cfg.ReceiveEndpoint(host, configuration.Queue, e =>
{
});
});
And I start it as following:
// start the bus
IBusControl bus = container.Resolve<IBusControl>();
bus.Start();
Unfortunately when RabbitMQ is down, and this is a scenario I have in my architecture, the method bus.Start()
hang for a while until it bombs and throw an exception.
Is there an alternative pattern that I can use so the application notifies via "log" that the Queue is down and I can try later to run bus.Start()
?
There is no need to manually retry
bus.Start()
as if you handle the exception thrown (RabbitMqConnectionException
), MassTransit (we're using v3.5.5) will keep on trying to establish a RabbitMQ connection in the background. Callingbus.Start()
a second time will always succeed even if RabbitMQ is still unavailable.In this scenario we catch the exception thrown on
bus.Start()
and evaluate it to see if it's a transient or permanent fault. If its permanent then terminate the application. If its transient then we start the application and then use Polly to retry any importantbus.Publish()
/bus.Send()
calls that fail whilst RabbitMQ is offline.