-
Following a short discussion on SO, I'm creating a discussion here as requested. The issue I want to clarify and resolve, is as follows: It seems that long running operations inside a consumer, triggered by a I have the following code, which can be pasted into the using Consumers;
using MassTransit;
using MassTransit.Mediator;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddMediator(cfg =>
{
// Even explicitly configuring a timeout of 40s (longer than the 35s delay in the consumer) does not fix the problem
cfg.AddConsumer<OrderStatusConsumer>(o => o.UseTimeout(t => t.Timeout = TimeSpan.FromSeconds(40)));
});
var provider = services.BuildServiceProvider();
var mediator = provider.GetRequiredService<IMediator>();
Guid orderId = NewId.NextGuid();
var client = mediator.CreateRequestClient<GetOrderStatus>();
var response = await client.GetResponse<OrderStatus>(new(orderId));
Console.WriteLine("Order Status: {0}", response.Message.Status);
namespace Consumers
{
public record GetOrderStatus(Guid OrderId);
public record OrderStatus(Guid OrderId, string Status);
class OrderStatusConsumer : IConsumer<GetOrderStatus>
{
public async Task Consume(ConsumeContext<GetOrderStatus> context)
{
await Task.Delay(30000); // Removing this makes the application work fine. Setting it 29000 or lower also works fine
await context.RespondAsync<OrderStatus>(new(context.Message.OrderId, "Pending"));
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you are using the request client (which has a default timeout of 30 seconds) and you need a longer timeout, you should increase the request timeout either when creating it or when calling |
Beta Was this translation helpful? Give feedback.
-
Thanks, this clarifies why this is happening! It would be nice if you could elaborate on the decision to use a different timeout than the one defined in the |
Beta Was this translation helpful? Give feedback.
If you are using the request client (which has a default timeout of 30 seconds) and you need a longer timeout, you should increase the request timeout either when creating it or when calling
GetResponse
.