Reputation: 1148
I use the MassTransit.AspNetCore
package to integrate masstransit
to asp.net core
. So I have the following code in my Startup.cs
class:
IBusControl CreateBus(IServiceProvider serviceProvider)
{
return Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host(Configuration["rabbitMqUrl"], h =>
{
h.Username(Configuration["rabbitMqUsername"]);
h.Password(Configuration["rabbitMqPassword"]);
});
});
}
services.AddMassTransit(CreateBus);
And the issue is that if the rabbit mq is not available my application tries to reconnect to the host. Is there any way to configure number of attempts - let's say stop trying to reconnect after 3 attempts so my application can run?
Upvotes: 0
Views: 334
Reputation: 33540
The bus.StartAsync()
method accepts a CancellationToken
, which can be used to cancel starting the bus. There is an overload that accepts a TimeSpan
which can be used to specify a timeout for the connection.
The hosted service also accepts a cancellationToken, but I'm not sure how ASP.NET Core determines what to pass to it and how to setup a timeout.
Upvotes: 1