SQS重复邮件处理 [英] SQS Duplicate messages handling
问题描述
我正在使用Amazons SQS
和另一台处理作业的计算机(工作程序)运行队列进程.我还使用supervisor
来确保queue:listen
始终在工作计算机上运行,但是当我定义numprocs=8
时(如laravel网站上的示例),作业执行了多次,因此发送了电子邮件几次等等.
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?
推荐答案
使用SQS,一旦工作人员拿走了一件物品,该工人有责任立即从SQS中删除该物品,以免其他工人也无法获得该物品.
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.
文档的此部分说明了删除项目所需的时间- http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html
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
由于您没有显示发送电子邮件的Laravel worker的代码,因此我只能猜测您不是立即删除SQS项目-而是仅在发送电子邮件之后才删除它.如果电子邮件发送部分所花费的时间超过了SQS可见性超时(如链接文档中所述),则其他工作人员也可以承担相同的任务.
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.
这篇关于SQS重复邮件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!