1

I have messages inside amazon SQS. for some of the messages I need to perform a delay of six hours before I can start working on them (the delay is a giving). one solution would be to do Thread.Sleep(6h). I don't like this solution because I'm afraid something will happen to the thread and I'll lose the data. another solution will be to read the message see if 6 hours have passed, and if not return the message to the queue. again I don't like it because the procedure will happen a lot. Is there any better solution ??

1 Answer 1

0

Can you create individual Multiple Queues and put the queue items separately.

Example 1:

You can have 6 queues like Queue0, Queue1, Queue2, Queue3, Queue4, Queue5 and use a hash-function like hash(x) = current-hour % 6 - this function will return values from 0 to 5 and you can put the items in Queue_f(x) and read the queues individually based on current time.

Example 2:

If the current time is 01:00 Hours you can create separate queues like Queue0700Hours, if the current time is 02:00 hours you can create a another new queue as Queue0800Hours like wise and go.

This way you are decoupling the need to wait / stop a processing and pick up the producers and consumers independently based on the current timestamp.

2
  • I thought about creating another dedicated queue. I was hoping I could avoid it. Isn't there out of the box solution Amazon provides for delaying a message for several hours?
    – Tsahi
    Nov 10, 2014 at 18:00
  • The out of the box way would be like adding items to the queue and reading them immediately by another process. Set the queue to have the visibility timeout of 6 hours. This way the queue item is picked as soon as it is pushed and when the item is picked - it is old re appear after 6 hours. To ensure and confidently process the items after 6 hours, you see the retry count to be 1. Nov 11, 2014 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.