首页 > 解决方案 > NServiceBus 可恢复性失败时发送消息

问题描述

有没有办法在且仅当 Recoverability 执行的所有重试都失败时才向 NServiceBus 发送消息?简而言之,我想向另一个队列发送一条新消息(同时它被发送到错误队列)。我不确定是否或如何插入管道来执行此操作。

我有一个行为,当我抛出一个特定的异常时,它通过向 NServiceBus 发送一个事件(绕过重试)来处理它,但是我有另一个用例,我想仅在重试失败后发送相同的事件。

class OperationFailedExceptionBehavior : Behavior<IIncomingLogicalMessageContext>
{
    public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next)
    {
        try
        {
            await next().ConfigureAwait(false);
        }
        catch (OperationFailedException ex)
        {
            //since we're catching the exception, retries will no longer occur.
            await context.Publish(new OperationFailedEvent(ex));
        }
    }
}

标签: c#nservicebus

解决方案


可能通知是您正在寻找的。您可以订阅错误通知,我认为它将为您提供实现上述要求所需的所有详细信息。

有关更多详细信息:https ://docs.particular.net/nservicebus/recoverability/subscribing-to-error-notifications


推荐阅读