Error handling 当请求处理程序失败时,NServiceBus 6回调客户端永远不会得到回调
使用NServiceBus6的回调功能,我找不到任何方法来警告客户端请求处理程序失败。请求处理程序将完成所有可恢复性步骤,并最终将消息放入错误队列。与此同时,客户只是坐在那里等待答复Error handling 当请求处理程序失败时,NServiceBus 6回调客户端永远不会得到回调,error-handling,callback,nservicebus,nservicebus6,request-response,Error Handling,Callback,Nservicebus,Nservicebus6,Request Response,使用NServiceBus6的回调功能,我找不到任何方法来警告客户端请求处理程序失败。请求处理程序将完成所有可恢复性步骤,并最终将消息放入错误队列。与此同时,客户只是坐在那里等待答复 // Client code (e.g. in an MVC Controller) var message = new FooRequest(); var response = await endpoint.Request<FooReponse>(message); // Handler code
// 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控制器/调用代码知道处理程序已永久失败?这是出于设计考虑。从客户端的角度来看,我建议您始终传入一个CancellationToken,它定义了允许请求者在请求调用中等待应答的时间
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
}
客户端域定义允许客户端请求异步等待应答的时间。有关取消的更多信息,请参阅设计的。从客户端的角度来看,我建议您始终传入一个CancellationToken,它定义了允许请求者在请求调用中等待应答的时间
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
}
客户端域定义允许客户端请求异步等待应答的时间。有关取消的更多信息,请参阅从未想过使用cancellationToken进行超时。有道理。谢谢从未想过使用cancellationToken进行超时。有道理。谢谢