Search code examples
.net-corerebusrebus-azureservicebus

Rebus with secondLevelRetriesEnabled enable retries doesn't stop retrying on IFailed<T> handler


I'm having an issue with rebus (that I'm sure it's me the problem) and here's the issue: I have second level retries enabled. In the normal handler I throw a FailFastException In the IFailed handler I got the message and I do a kind of "delayed" retry (I defer 10 times with a delay of 30s) After all 10 re-tries, I want to finish (aka send to error queue) and for this I'm just throwing a new exception and it "kinda" works.

The issue is in the last step, when I throw the last exception, rebus still retries 5 times (default). So actually I'm retrying 10 times (defer) + 5 times(rebus default fast retry).

Is there any way I can only do the 10 (deferred) times? I can forward to the dead letter queue manually but... it seems hacky.

Also, I use fleet manager, does forwarding the message to the error queue means the message will also be in the fleet manager?


Solution

  • Is there any way I can only do the 10 (deferred) times? I can forward to the dead letter queue manually but... it seems hacky.

    Yes, but it requires a little bit of manual work 🙂 you can do something like this in your 2nd level retry handler:

    try
    {
        await TrySomethingAlternativeAsync();
    }
    catch(Exception exception) 
    {
        // bummer, it still fails!
        // 
        // just deadletter the message now then
        await bus.Advanced.TrandportMessage.Deadletter(exception);
    }
    

    Also, I use fleet manager, does forwarding the message to the error queue means the message will also be in the fleet manager?

    Yes 🙂