Search code examples
.netrabbitmqesbmasstransit

MassTransit process message in the future


I'm evaluating MassTransit with RabbitMQ for a project and we want to be able to delay the processing of a message to a certain time.

The objective is the following:

  • A user does some things that affect other users
  • A message is sent to the bus to notify the affected users an hour later
  • User does more things and sends more notifications
  • An hour passes and:
    • It's been more than an hour since last summary: The message is processed, collects all pending notifications for each user, sending them a summary if there is at least one.
    • It's less than an hour since last summary: The message is not processed and is queued again another hour.

The thing is that many things can be notified so we don't want to send them immediately but summarized later. Can this be done with MassTransit and RabbitMQ?


Solution

  • I think you would want to split this into two stages, so messages are processed when they arrive, but not acted on until required.

    1. The MassTransit process receives the message, and persists the notification in a data store of some kind.

    2. You also have a summarizing process, which runs occasionally, looks at the data store to see what's outstanding, and sends the summarized notifications to the user if it's more than an hour since their last summary.

    Edit: It may be possible to hack RabbitMQ to do this, see http://www.javacodegeeks.com/2012/04/rabbitmq-scheduled-message-delivery.html