1

As per my understanding default value for maxDeliveryAttempts is 5?
Even after explicitly setting the value of 5 at times I've observed retry to exceed 5 ( upto > 10 recently). Configurations are SetNumberOfWorkers:5,SetMaxParallelism: 10, SimpleRetryStrategy(maxDeliveryAttempts: 5, secondLevelRetriesEnabled: true),

Within handler, if we are unable to process the message as a best-suggested practice should I explicitly throw an exception, return null or just let the exception propagate ( at the moment I catch the exception log and rethrow same) - can this impact the behaviour?

I've also implemented IHandleMessages> to do some house keeping. Note: using rebus with rabbitmq

Karan
  • 65
  • 5

1 Answers1

1

First off, "best practice" with Rebus is to let exceptions bubble out of the handler and let Rebus do the logging. It will log each failed processing attempt as a WARNING, and then it will log all of the caught exceptions as an AggregateException as an ERROR when moving the message to the error queue.

Unless you enable 2nd level retries :) in that case, Rebus will proceed on to a second round of deliveries after the initial 5 WARNINGs, only dispatching the message as an IFailed<TMessage>.

If the subsequent five delivery attempts also fail (e.g. because there's no handler that implements IHandleMessages<IFailed<YourMessage>>), then you will get an additional 5 WARNINGs in the log, followed by an ERROR, when the message finally gets moved to the error queue.

I hope that makes it clearer :) let me know if there's something I should explain in more detail.

mookid8000
  • 18,258
  • 2
  • 39
  • 63
  • I am catching the exception in handler as I want to write the custom text in logs, after logging I throw; the exception. After the first 5 attempts of 1st level tries, 2nd level retry will kick in. In the handler for IFailed, I do housekeeping if it fails during same, I understand 2nd level attempt will retry for another 5 times, thus making the count to 10. In my case, there is no failure in the 2nd level attempt ( housekeeping is successful) I should only see 5 attempts ( for the 1st level tries) - if my understanding is correct I am not sure I see 10 attempts by 1st level tries? – Karan Jan 30 '19 at 01:55
  • If you want to include custom text with your exceptions, it's good practice to throw a new exception, including the caught exception as an inner exception. E.g. like this: `try { ... } catch(Exception exception) { throw new ApplicationException("OMG something bad happened", exception); }` – mookid8000 Jan 30 '19 at 12:27
  • Thanks, it does make sense to throw new ApplicationException instead of just throw. Also any thoughts on my understanding of 1st & 2nd level retries? and anything on top of your head which might be causing handler implementation of IHandlerMessage being invoked more than 5 times? – Karan Jan 30 '19 at 20:51
  • You might want to read [the wiki page about Rebus' error handling](https://github.com/rebus-org/Rebus/wiki/Automatic-retries-and-error-handling) – mookid8000 Jan 31 '19 at 08:43
  • figured out the issue, we have multiple clusters of rabbitmq & multiple instance of consumer services running, and it seems when an exception occurs while processing the message the duplicate handling of messages happens. During this scenario for some reason instances of our consumer service get the message and they start processing same, till it gets moved to error queue. Any suggestion on how to tackle this scenario ( I can think of setting a flag or changing status of the message being processed and other handlers to bypass the handling if flag/status is set)? – Karan Feb 05 '19 at 04:07
  • played around some more, ran 2 instance's of my service both using rebus handle messages (IHandle) and both also implement IHandle>, both services configured to fail to process the message in IHandle. I noticed hanlder in both services got invoked in following pattern Service1>Service2>Service1>Service2... till 5 times for service1 and 5 time fo service2. Thus in total attempting to process messages 10 times. Is this the intented behaviour? – Karan Feb 12 '19 at 05:33