当 RabbitMQ 不可访问时,MassTransit ISendEndpoint.Send 方法不会抛出异常
MassTransit ISendEndpoint.Send method doesn't throw exception when RabbitMQ is unreachable
具有以下代码片段:
try
{
UpdateCommand updateCommand = new UpdateCommand
{
Name = "Update"
};
await sendEndpoint.Send(updateCommand);
}
catch (BrokerUnreachableException ex)
{
}
catch (Exception ex)
{
}
当调用 Send 方法并且没有与 RabbitMQ 的连接时,不会抛出异常。它应该像这样工作吗?
我试过像这样将 SendObserver 连接到我的 ReceiveEndpoint:
ISendObserver sendObserver = new UpdateSendObserver();
cfg.ReceiveEndpoint(EventBusConstants.UpdateQueue, c => {
c.ConfigureConsumer<UpdateCommandConsumer> (ctx);
cfg.ConnectSendObserver(sendObserver);
});
但是当没有与 RabbitMQ 的连接时,它不会命中任何 PreSend、PostSend、SendFault 方法。
作为 explained in the GitHub Discussion,您可以使用 CancellationToken
取消对 Send
/Publish
的调用。如果与代理的连接不可用,则传输使用重试策略。
具有以下代码片段:
try
{
UpdateCommand updateCommand = new UpdateCommand
{
Name = "Update"
};
await sendEndpoint.Send(updateCommand);
}
catch (BrokerUnreachableException ex)
{
}
catch (Exception ex)
{
}
当调用 Send 方法并且没有与 RabbitMQ 的连接时,不会抛出异常。它应该像这样工作吗?
我试过像这样将 SendObserver 连接到我的 ReceiveEndpoint:
ISendObserver sendObserver = new UpdateSendObserver();
cfg.ReceiveEndpoint(EventBusConstants.UpdateQueue, c => {
c.ConfigureConsumer<UpdateCommandConsumer> (ctx);
cfg.ConnectSendObserver(sendObserver);
});
但是当没有与 RabbitMQ 的连接时,它不会命中任何 PreSend、PostSend、SendFault 方法。
作为 explained in the GitHub Discussion,您可以使用 CancellationToken
取消对 Send
/Publish
的调用。如果与代理的连接不可用,则传输使用重试策略。