SQS Duplicate messages handling

帅比萌擦擦* 提交于 2019-12-04 05:02:46

问题


I am running a queue process using Amazons SQS and a separate machine that processes the jobs (a worker). I am also using the supervisor to make sure the queue:listen is always running on the worker machine, yet when I define numprocs=8 (like the example on laravel's website) jobs are being executed more than once hence emails are being sent couple of times etc'.

Any Idea how can I make sure a job is executed only once even if I am running multiple worker processes and machines?


回答1:


With SQS, once a worker takes an item - it is the worker's responsibility to immediately delete the item from SQS so that other workers will not get the item as well.

This part of the documentation explains what amount of time you are allowed for, to delete the item - http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html

Since you did not show the code of your e-mail sending Laravel worker, I can only guess that you are not deleting the SQS item immediately - but instead maybe deleting it only after the e-mail was sent. Should the e-mail sending part take more than SQS Visibility Timeout (described in the link document), it would make sense the same task is picked up by other workers.



来源:https://stackoverflow.com/questions/37543355/sqs-duplicate-messages-handling

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