Rebus - Deferred Message, exactly one message handler

822 views Asked by At

I was wondering if the Rebus Service Bus can handle the following use cases:

  • Queue messages for a future date
  • if there is a message ProcessInvoice with a context like Customer Id: 1000, can we have exactly one handler executing the message. So in case the message is duplicated, it does not get processed again.

Thanks

1

There are 1 answers

0
mookid8000 On

Sure - Rebus can bus.Defer a message some TimeSpan into the future - e.g. to postpone the delivery of a message to some specific date, something like this could do it:

var delay = utcTimeOfWhenToDeliverTheMessage - DateTime.UtcNow;

bus.Defer(delay, messageToPostpone);

which requires that a timeout manager has been configured. You can configure a timeout manager by going

Configure.With(...)
    .(...)
    .Timeouts(t => t.(...))

in the Rebus configuration spell.

If you want to guarantee that a given message is processed only once even though duplicates might be delivered, there's a couple of things to consider - it's hard to tell you the easiest way to handle it, because sometimes it can be easy to simply make the performed action idempotent, other times you'd need to track the ID of the processed message etc.