问题
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