SQS - Delivery Delay of 30 minutes

假装没事ソ 提交于 2019-11-30 03:51:45

问题


From the documentation of SQS, Max time delay we can configure for a message to hide from its consumers is 15 minutes - http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html

Suppose if I need to hide the messages for a day, what is the pattern? For eg. I want to mimic a daily cron for doing some action.

Thanks


回答1:


Visibility timeout can do up to 12 hours. I think you can hack something together where you process a message but don't delete it and next time it is processed its been 12 hours. So a queue with one message and visibility timeout of 12 hours. That gets you a 12 hour cron.




回答2:


The simplest way to do this is as follows:

SQS.push_to_queue({perform_message_at : "Thursday November 2022"},delay: 15 mins)

Inside your worker

message = SQS.poll_messages
if message.perform_message_at > Time.now
   SQS.push_to_queue({perform_message_at : "Thursday November 
   2022"},delay:15 mins)
else
   process_message(message)
end

Basically push the message back to the queue with the maximum delay and only process it when its processing time is less than the current time.

HTH.




回答3:


Cloudwatch is likely a better way to do it. You can use a createEvent API with the timer, and have it trigger either a lambda function or an API call to whatever comes next.

Another way to do is to use the "wait" utility in an AWS step function.

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

In any case, unless you are extremely sure you will never need anything more than 15 minutes, the SQS backdoor to add the delay seems hacky.




回答4:


Two thoughts.

  1. Untested. Perhaps publish to and SNS topic that has no SQS queues. When delivery needs to happen, subscribe the queue to the topic. (I've not done this, I'm not sure if this would work as expected)
  2. Push messages as files to a central store (like S3). Create a worker that looks at the time created timestamp and decides whether to publish them to a queue or not. If created >= 1d ago, publish.


来源:https://stackoverflow.com/questions/31881470/sqs-delivery-delay-of-30-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!