我应该何时删除SQS中的消息? [英] When should I delete messages in SQS?

查看:97
本文介绍了我应该何时删除SQS中的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序包含:

  • 1个Amazon SQS消息队列
  • n名工人

工人具有以下逻辑:

 1. Wait for message from SQS queue
 2. Perform task described in message
 3. Delete the message from the SQS queue
 4. Go to (1)

我希望每条消息只能由一个工作人员接收,以避免重复工作.

I want each message to be received by only one worker to avoid redundant work.

是否存在使用SQS将消息标记为进行中"的机制,以便其他轮询器不会收到该消息?

Is there a mechanism to mark a message as "in progress" using SQS, so that other pollers do not receive it?

或者,是否应该在收到消息后立即将其删除?

Alternatively, is it appropriate to delete the message as soon as it is received?

 1. Wait for message from SQS queue
 2. Delete the message from the SQS queue
 3. Perform task described in message
 4. Go to (1)

如果我采用这种方法,是否有办法在工作人员崩溃(步骤(3)失败)的情况下恢复收到但未处理的消息?

If I follow this approach, is there a way to recover received but unprocessed messages in case a worker crashes (step (3) fails)?

这个问题特定于Spring,其中包含各种魔术.

This question is specific to Spring, which contains all sorts of magic.

推荐答案

SQS消息被视为正在进行中";使用者从队列中收到但尚未从队列中删除它.这些消息对其他使用者不可见.

An SQS message is considered to be "inflight" after it is received from a queue by a consumer, but not yet deleted from the queue. These messages are not visible to other consumers.

在SQS消息传递中,消息被认为是在进行中"过程中进行的.如果:

In SQS messaging, a message is considered in "inflight" if:

  1. 您的消费者已收到它,并且
  2. 可见性超时尚未到期,并且
  3. 您尚未删除它.

SQS的设计使您可以调用ReceiveMessage并向您发送一条消息进行处理.您有一些时间(可见性超时)来对此消息执行处理.在此可见性"期间,超时,如果再次调用ReceiveMessage,则不会向您返回任何正在处理您的消息的工作程序.它是隐藏的.

SQS is designed so that you can call ReceiveMessage and a message is given to you for processing. You have some amount of time (the visibility timeout) to perform the processing on this message. During this "visibility" timeout, if you call ReceiveMessage again, no worker will be returned the message you are currently working with. It is hidden.

可见性超时到期后,该消息将能够返回到将来的ReceiveMessage调用.如果消费者以某种方式失败,则可能会发生这种情况.如果该过程成功,则可以删除该消息.

Once the visibility timeout expires the message will be able to be returned to future ReceiveMessage calls. This could happen if the consumer fails in some way. If the process is successful, then you can delete the message.

ReceiveMessage调用中隐藏的消息数是进行中"消息.数字.当前,默认情况下会默认设置SQS队列,以允许最多120,000条消息进行中".

The number of messages that are hidden from ReceiveMessage call is the "inflight" number. Currently a SQS queue is set by default to allow a max of 120,000 messages to be "inflight".

http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html

这篇关于我应该何时删除SQS中的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆