简体   繁体   English

我在获取响应请求取消并引发异常之前发送请求时,在asp.net核心中使用Masstransit Requst响应

[英]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.

相关问题 MassTransit Azure 服务总线请求-响应 ASP.NET 核心 RequestTimeoutException - MassTransit Azure Service Bus Request-Response ASP.NET Core RequestTimeoutException 发送请求并从我的asp.net中的php获取响应 - send Request and get response from php in my asp.net ASP.NET 内核 Web API 使用请求/响应模式处理异常 - ASP.NET Core Web API exception handling with Request/Response Pattern ASP NET核心Serilog:请求,响应和异常日志的不同文件 - ASP NET core Serilog : Different files for Request, Response and Exception logs ASP.NET 请求 model 与响应 model 不同时的核心验证 - ASP.NET Core validation when request model is different to response model asp.net中的捷克语和请求/响应问题 - Czech and Request/Response problems in asp.net masstransit请求/响应:在使用者中获取呼叫者超时 - masstransit request/response: get caller timeout in consumer 如何发送ajax请求以请求XML响应到asp.net MVC 4控制器? - How to send ajax request to request XML response to asp.net MVC 4 controller? 使用Fiddler将请求发送到具有DataContract中未定义的其他节点的ASP.NET服务器,并期望它引发异常 - Using Fiddler's to send request to a ASP.NET server with additional node not defined in DataContract, and expecting it to throw an exception 当我向 Web API Controller 中的 Z9E0DA8438E1E38A8DDZCE7C30 中的 Web 发送多部分请求时使用哪种格式化程序? - Which formatter is used when I send a multipart request to a Web API Controller in ASP.NET CORE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM