Is there a way to send a message to NServiceBus when, and only when, all the retries performed by Recoverability has failed? In short, I want to send a new message to another queue (at the same time it gets sent to the error queue). I not sure if, or how, I can plug into the pipeline to do this.
I have a behavior below that when I throw a specific exception, it handles it by sending an event to NServiceBus (bypassing retries), but I have another use case where I want to send that same event only after retries have failed as well.
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));
}
}
}