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 工作人员的代码,我只能猜测您不会立即删除 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屋!