I have an application with masstransit and rabbitmq. some of my requests resulted in timeout.
I tried using UseTimeout but it did not work:
services.AddMassTransit(x =>
{
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host(configuration["RabbitMqUri"], h =>
{
h.Username(configuration["RabbitMqUsername"]);
h.Password(configuration["RabbitMqPassword"]);
});
cfg.UseTimeout(timeoutConfigurator => timeoutConfigurator.Timeout = TimeSpan.FromSeconds(120));
cfg.ConfigureEndpoints(context);
}
}
I know i can set timeout as following:
private async Task<Result> TempTimeout(IRequestClient<TempTimeoutCommand> requestClient, CancellationToken cancellationToken)
{
var res = await requestClient.GetResponse<TempTimeoutResponse>(
new TempTimeoutCommand(),
cancellationToken,
RequestTimeout.After(s: 100)
);
return res.Message.Result;
}
Is it possible to configure timeout for the whole application?
UseTimeout
is not the way. Currently there isn't a method to configure the client factory with a specific timeout, but I have a commit pending that will add the ability to configure the default request timeout.
It will look like:
services.AddMassTransit(x =>
{
x.SetDefaultRequestTimeout(...)