0

I am using Masstransit Request-Response in Asp.NetCore When I send Request before I get Response, Request is getting Cancelled and throwing this Exception

System.Threading.Tasks.TaskCanceledException: A task was canceled.

I have downloaded masstransit codes and debugging my project with it. I understand ClientRequestHandle dispose and cancel requests before my response is received.

I checked Consumer side and it works successfully and sends Response as expected.

Morse
  • 8,258
  • 7
  • 39
  • 64
  • this is my code: try { using (var handle = _getOrderInfoRequestClient.Create(new GetThirdPersonInsuranceProductAmountCommand(productId))) { var response = await handle.GetResponse>(); if (!response.Message.IsSuccess) throw new DomainException(response.Message.Message); return Convert.ToDecimal(response.Message.ResponseValue.Value); } } catch (Exception ex) { throw; } – hadi nasehi Feb 16 '19 at 14:46

1 Answers1

1

When using the RequestHandle<T>, you need to maintain a reference to the handle until the request is completed and the response is received (or a timeout or fault occurs).

You can simplify this by using a single line method, of:

var response = await requestClient.GetResponse<T>(request);

If you need to add things to the request, such as headers, etc. then you need to keep the handle around until it's completed.

using(var handle = requestClient.Create(request))
{
    var response = await handle.GetResponse<T>();
}
Chris Patterson
  • 28,659
  • 3
  • 47
  • 59