NServiceBus 6 callback client never gets a callback when the request handler fails

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-10 20:14:02

问题


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

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


回答1:


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
}

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



来源:https://stackoverflow.com/questions/48675609/nservicebus-6-callback-client-never-gets-a-callback-when-the-request-handler-fai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!