Exponential interval retries : common 10 Time, Each interval : Current retries * 60 secondĮp.UseMessageRetry(r => r.Exponential(10, TimeSpan.FromSeconds(60), TimeSpan.FromHours(24), TimeSpan.FromSeconds(60))) Įp.UseMessageRetry(r => r.Incremental(10, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(50))) Multiple interval retries :5 For the first time in seconds ,5+10 Second time in seconds ,5+10+15 The third time in secondsĮp.UseMessageRetry(r => r.Intervals(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(15))) Interval retries : Try again 10 Time, Each interval 10 secondĮp.UseMessageRetry(r => r.Interval(10, TimeSpan.FromSeconds(10))) Try again now : A total of consecutive retries 10 TimeĮp.UseMessageRetry(r => r.Immediate(10)) Var busControl = (cfg =>Į.Consumer(() => new SubmitOrderConsumer(sessionFactory)) UseMessageRetry var sessionFactory = CreateSessionFactory() Throw new Exception("Very bad things happened") Public Task Consume(ConsumeContext context)
Redelivery is a form of retry (some refer to it as second-level retry) where the message is removed from the queue and then redelivered to the queue at a future time.2.6.8 RabbitMQ - Masstransit exception handlingĮxception public class SubmitOrderConsumer : In these situations, it's best to dust off and nuke the site from orbit - at a much later time obviously. Some errors take a while to resolve, say a remote service is down or a SQL server has crashed. If a DataException is thrown matching the filter expression, it wouldn't be handled by the second retry filter, but would be handled by the first retry filter. In the above example, if the consumer throws an ArgumentNullException it won't be retried (because it would obvious fail again, most likely). You can use multiple calls to these methods to specify filters for multiple exception types: No further filtering is possible if this version is used. Non-generic version that needs one or more exception types as parameters. You can also specify a function argument that will filter exceptions further based on other parameters.
With no argument, all exceptions of specified type will be either handled or ignored. Generic version Handle and Ignore where T must be derivate of System.Exception. A filter can have either Handle or Ignore statements, combining them has unpredictable effects.
Specify exception types using either the Handle or Ignore method. To implement this, you can use an exception filter. Sometimes you do not want to always retry, but instead only retry when some specific exception is thrown and fault for all other exceptions. Retry after a steadily increasing delay, up to the retry limitĮach policy has configuration settings which specifies the expected behavior. Retry after an exponentially increasing delay, up to the retry limit Retry after a delay, for each interval specified Retry after a fixed delay, up to the retry limit When configuring message retry, there are several retry policies available, including: Policy
Learn how to configure message retry in this short video (opens new window).