[英]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 我使用
Masstransit
在请求-响应 Asp.NetCore
当我发送请求之前,我得到响应,要求越来越取消和引发此异常
System.Threading.Tasks.TaskCanceledException: A task was canceled.
I have downloaded masstransit
codes and debugging my project with it. 我已经下载了
masstransit
代码并使用它调试我的项目。 I understand ClientRequestHandle
dispose and cancel requests before my response is received. 我理解
ClientRequestHandle
在收到我的响应之前会处理并取消请求。
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). 使用
RequestHandle<T>
,您需要维护对句柄的引用,直到请求完成并接收到响应(或者发生超时或错误)为止。
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>();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.