当请求处理程序失败时,NServiceBus 6回调客户端永远不会获得回调 [英] NServiceBus 6 callback client never gets a callback when the request handler fails

查看:52
本文介绍了当请求处理程序失败时,NServiceBus 6回调客户端永远不会获得回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NServiceBus 6的回调功能,我发现没有办法警告客户端请求处理程序失败.请求处理程序将执行所有可恢复性步骤,并最终将消息放入错误队列.同时,客户只是坐在那里等待答复.

Using NServiceBus 6's Callback feature I have found no way to alert the client that the request handler failed. The request handler will go through all the recoverability steps, and eventually put the message into the error queue. Meanwhile, the client just sits there waiting for its reply.

// Client code (e.g. in an MVC Controller)
var message = new FooRequest();
var response = await endpoint.Request<FooReponse>(message);

// Handler code
public class FooRequestHandler : IHandleMessages<FooRequest>
{
    Task Handle(FooRequest message, IMessageHandlerContext context)
    {
        throw new Exception("Fails before the reply");
        return context.Reply(new FooResponse());
    }
}

在上述情况下,如何让MVC控制器/调用代码知道处理程序永久失败?

In the above situation, how can I let the MVC controller/calling code know that the handler has permanently failed?

推荐答案

这是设计使然.从客户的角度来看,我建议您始终传入 CancellationToken ,该代码定义了允许请求者等待多久才能回复请求调用.

That is by design. From a client perspective I'd recommend you to always pass in a CancellationToken that defines how long the requester is allowed to wait for a reply into the request call.

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(5)); // your SLA timeout
var message = new Message();
try
{
    var response = await endpoint.Request<FooRequest>(message, cancellationTokenSource.Token)
                                 .ConfigureAwait(false);
}
catch (OperationCanceledException)
{
    // Exception that is raised when the CancellationTokenSource is canceled
}

客户端域定义允许客户端请求异步等待答案的时间.有关取消的更多信息,请参考 https://docs.particular.net/nservicebus/messaging/callbacks?version = callbacks_3#cancellation

The client domain defines how long a client request is allowed to asynchronously wait for an answer. For more information about cancellation refer to https://docs.particular.net/nservicebus/messaging/callbacks?version=callbacks_3#cancellation

这篇关于当请求处理程序失败时,NServiceBus 6回调客户端永远不会获得回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆