Second level retries in Rebus with Rabbitmq -


i have scenario call api in 1 of handlers , api can go down 6 hours per month. therefore, designed retry logic 1sec retry, 1 minute retry , 6 hour retry. works fine found long delay retries not option.could please give me experience this?

thank you!

if you, use rebus' ability defer messages future implement functionality.

you need track number of failed delivery attempts manually though, attaching , updating headers on deferred message.

something should trick:

public class yourhandler : ihandlemessages<makeexternalapicall> {     const string deliveryattemptheaderkey = "delivery-attempt";      public yourhandler(imessagecontext context, ibus bus)     {         _context = context;         _bus = bus;     }         public async task handle(makeexternalapicall message)     {         try         {             await makecalltoexternalwebapi();         }         catch(exception exception)         {             var deliveryattempt = getdeliveryattempt();              if (deliveryattempt > 5)             {                 await _bus.advanced.transportmessage.forward("error");             }             else             {                 var delay = getnextdelay(deliveryattempt);                 var headers = new dictionary<string, string> {                     {deliveryattemptheaderkey, (deliveryattempt+1).tostring()}                 };                  await bus.defer(delay.value, message, headers);             }         }         }      int getdeliveryattempt() => _context.headers.trygetvalue(deliveryattemptheaderkey, out var deliveryattempt)         ? deliveryattempt         : 0;      timespan getnextdelay() => ... } 

when running in production, please remember configure kind of persistent subscription storage – e.g. sql server – otherwise, deferred messages lost in event of restart.

you can configure (after having installed rebus.sqlserver package):

configure.with(...)     .(...)     .timeouts(t => t.storeinsqlserver(...))     .start(); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -