Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the recommended way to queue "delayed execution" messages via ServiceStack/Redis MQ?

I would like to queue up messages to be processed, only after a given duration of time elapses (i.e., a minimum date/time for execution is met), and/or at processing time of a message, defer its execution to a later point in time (say some prerequisite checks are not met).

For example, an event happens which defines a process that needs to run no sooner than 1 hour from the time of the initial event.

Is there any built in/suggested model to orchestrate this using https://github.com/ServiceStack/ServiceStack/wiki/Messaging-and-Redis?

like image 380
JesseP Avatar asked Aug 26 '13 18:08

JesseP


1 Answers

I would probably build this in a two step approach.

  1. Queue the Task into your Queueing system, which will process it into a persistence store: SQL Server, MongoDB, RavenDB.

  2. Have a service polling your "Queued" tasks for when they should be reinserted back into the Queue.

Probably the safest way, since you don't want to lose these jobs presumably.

If you use RabbitMQ instead of Redis you could use Dead Letter Queues to get the same behavior. Dead letter queues essentially are catchers for expired messages.

So you push your messages into a queue with no intention of processing them, and they have a specific expiration in minutes. When they expire they pop over into the queue that you will process out of. Pretty slick way to queue things for later.

like image 163
Khalid Abuhakmeh Avatar answered Oct 30 '22 15:10

Khalid Abuhakmeh