AWS:多个实例读取SQS(AWS: multiple instances reading SQS)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
AWS:多个实例读取SQS(AWS: multiple instances reading SQS)

简单的问题:我想在亚马逊上运行一个自动缩放组,它启动了多个实例来处理来自SQS队列的消息。 但是,我怎么知道这些实例没有处理相同的消息呢?

处理完后,我可以从队列中删除消息。 但是如果它还没有被删除,并且仍然被一个实例处理,另一个实例可以下载同样的消息并处理它,对我来说也是如此。

Simple question: I want to run an autoscale group on Amazon, which fires up multiple instance which processes the messages from a SQS queue. But how do I know that the instances aren't processing the same messages?

I can delete a message from the queue when it's processed. But if it's not deleted yet and still being processed by an instance, another instance CAN download that same message and processing it also, to my opinion.

最满意答案

除了SQS错误地发送相同信息的相当远的可能性(即使不太可能,您仍需要考虑这一点),我怀疑您的问题源于对SQS“可见性超时”概念的不熟悉。 “

紧接在组件收到消息后,消息仍然在队列中。 但是,您不希望系统中的其他组件再次接收和处理该消息。 因此,Amazon SQS会以可见性超时阻止它们,这是Amazon SQS阻止其他消费组件接收和处理该消息的时间段。

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html

这是让多个队列跑步者看到相同的消息。 一旦可见性超时到期,消息将再次传递给队列消费者,除非您将其删除,或者超过配置的最大配送数量(在此时它被删除或进入单独的死信队列,如果您配置了一个)。 如果作业所花的时间超过配置的可见性超时,则您的客户也可以向SQS发送请求,以更改该单个消息的可见性超时。


更新:

由于最初编写了这个答案,因此SQS在一些AWS地区引入了FIFO队列。 它们采用上述相同的逻辑进行操作,但保证了按顺序交付和额外的安全措施,以保证偶尔发生的重复消息传递不会发生。

FIFO(先入先出)队列旨在增强应用程序之间的通信,当操作和事件的顺序非常关键时,或者不能容忍重复时。 FIFO队列也提供了精确的一次处理,但仅限于每秒300个事务(TPS)。

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html

将应用程序切换到FIFO队列确实需要更改一些代码,并且需要创建新的队列 - 现有队列不能更改为FIFO。

Aside from the fairly remote possibility of SQS incorrectly delivering the same message more than once (which you still need to account for, even though it is unlikely), I suspect your question stems from a lack of familiarity with SQS's concept of "visibility timeout."

Immediately after the component receives the message, the message is still in the queue. However, you don't want other components in the system receiving and processing the message again. Therefore, Amazon SQS blocks them with a visibility timeout, which is a period of time during which Amazon SQS prevents other consuming components from receiving and processing that message.

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html

This is what keeps multiple queue runners from seeing the same message. Once the visibility timeout expires, the message will be delivered again to a queue consumer, unless you delete it, or it exceeds the maximum configured number of deliveries (at which point it's deleted or goes into a separate dead letter queue if you have configured one). If a job will take longer than the configured visibility timeout, your consumer can also send a request to SQS to change the visibility timeout for that individual message.


Update:

Since this answer was originally written, SQS has introduced FIFO Queues in some of the AWS regions. These operate with the same logic described above, but with guaranteed in-order delivery and additional safeguards to guarantee that occasional duplicate message delivery cannot occur.

FIFO (First-In-First-Out) queues are designed to enhance messaging between applications when the order of operations and events is critical, or where duplicates can't be tolerated. FIFO queues also provide exactly-once processing but are limited to 300 transactions per second (TPS).

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html

Switching an application to a FIFO queue does require some code changes, and requires that a new queue be created -- existing queues can't be changed over to FIFO.

更多推荐

本文发布于:2023-04-24 20:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/cfe84e765c80f5a184a7fac86f4a191c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   实例   AWS   SQS   reading

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!