Reputation: 15454
My goal is to make request-response from API Gateway to microservice. I want request to be durable (not expiring), but response should be expiring (if no consumer will receive response within let's say 30s then it should expire). I am using RequestClient in API GW request handler (request scope). By default timeout is set by MassTransit to 30s and after this time request is removed from the queue. It's here in MassTransit code: https://github.com/MassTransit/MassTransit/blob/5e2a416384f005c392ead139f5c4af34511c56db/src/MassTransit/RequestTimeout.cs#L7.
First of I tried to set timeout in my request client like that (using RabbitMQ):
// on request client level
cfg.AddRequestClient<ICreateGroupPayload>(RequestTimeout.None);
// and/or
// on .GetResponse() level
var response = await _createGroupClient.GetResponse<ICreateGroupResult>(new
{
Name = payload.Name,
Description = payload.Description
}, new CancellationToken(), RequestTimeout.None);
But neither of those options work. Still message has default 30s TTL.
Upvotes: 0
Views: 8001
Reputation: 33457
You can configure a default timeout when registering the request client:
cfg.AddRequestClient<ICreateGroupPayload>(RequestTimeout.After(s:20));
And then, when sending the request, you can override the TimeToLive using a header in the message initializer:
var response = await _createGroupClient.GetResponse<ICreateGroupResult>(new
{
Name = payload.Name,
Description = payload.Description,
__TimeToLive = TimeSpan.FromYears(1)
}, httpContext.CancellationToken);
That will replace the default value (which matches the request timeout, by default) with the new value.
Upvotes: 4