简体   繁体   中英

Im usisng Masstransit Requst Response in asp.net core when I Send Request before get Response Request Canceling and throw Exception

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.

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>();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM