Search code examples
architecturescheduled-tasksnservicebusservicebus

How to architect scheduled tasks in a message based architecture?


I have an order web service that has a method for creating orders. When the method is invoked, a message is send to the service bus and gets handled by an order message handler.

On a daily and monthly basis I have to generate an order report. Normally I would have the order message handler storing the order in the database and then have a scheduled task that reads from the database and generates a report. But I was wondering if there is a more message oriented way of doing this?

I thought about having the order message handler publishing a message that various reporting services (e.g. daily and monthly) can subscribe to. The messages would be accumulated on a given queue until the services are activated at given intervals (daily / monthly). The services would then process messages on their queue and generate a report. Is this the way to go or am I way off?

Any pointers will be greatly appreciated.

Update

Is it (with NServiceBus) possible to keep messages in a publisher queue and then only publish them at a given interval? Or should it be the other way around so the publisher publishes immediately and the handling by the subscriber is scheduled?


Solution

  • NServiceBus implements a concept called Sagas for long-running processes. Have a look at http://nservicebus.com/Sagas.aspx I think the Timeout section refers to what you are looking for.