Hello,
I'm developing web based solution using MassTransit + RabbitMQ as transport. Some time ago I noticed that when I run my integration tests some of them start unexpectedly and very inconsistently hanging for a very loooong time.
After short investigation I found out that my code hangs somewhere inside ServiceBus.Publish<T>(T message) method.
Unfortunately MassTransit documentation and blog posts that I found do not answer what is the reason and how to solve this problem. Hopefully here somebody could help to resolve it.
Here is how I initialize my service bus:
ServiceBusFactory.New(sbc =>
{
sbc.ReceiveFrom(busAddress);
sbc.UseRabbitMq(r =>
{
r.ConfigureHost(new Uri(busAddress),
cfg =>
{
if (!string.IsNullOrEmpty(busUser) && !string.IsNullOrEmpty(busPass))
{
cfg.SetPassword(busPass);
cfg.SetUsername(busUser);
}
});
});
sbc.UseControlBus();
sbc.SetCreateMissingQueues(true);
sbc.SetCreateTransactionalQueues(true);
sbc.SetNetwork("workgroup");
sbc.UseBsonSerializer();
sbc.SetDefaultRetryLimit(2);
sbc.SetDefaultTransactionTimeout(new TimeSpan(0, 0, timeoutSec));
sbc.Validate();
});
timeoutSec value is 10
Service bus is initialized once and registered in Autofac container.
Publishing happens by calling IServiceBus.Publish(...) method.
One of the solutions is to wrap Publish(...) method into Task and use Task.Wait(...) method to enforce timeout but this does not look like a good solution.
I would be really appreciated for any kind of help!
Thank you!