AWS SQS 发件人设置消息可用于消费者的时间

AWS SQS sender setting a time for message to be avilable for the consumer

我在 AWS SQS 中看到一个名为 visibility timeout 的选项,它为其他消费者设置一个时间来忽略一个正在处理的消息。 是否有一个选项可以在消息实际可供消费者使用之前设置时间,可以在消息实际插入队列时设置

有这样的选项,但它是队列级别的选项,不是消息级别的选项:

You can use the CreateQueue action to create a delay queue by setting the DelaySeconds attribute to any value between 0 and 900 (15 minutes). You can also change an existing queue into a delay queue using the SetQueueAttributes action to set the queue's DelaySeconds attribute

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

当该值为非零时,所有消息在最初对任何消费者可见之前都会延迟指定的秒数。

找到一个名为 Amazon SQS 消息计时器的选项 Amazon SQS 消息计时器允许您为添加到队列的消息指定初始不可见期。例如,如果您 发送 DelaySeconds 参数 设置为 45 的消息,则消息在队列中停留的前 45 秒内对消费者不可见。 DelaySeconds 的默认值为 0。

要设置适用于队列中所有邮件的延迟时间,请使用延迟队列。单个消息的消息计时器设置 覆盖适用于整个延迟队列的任何 DelaySeconds 值

有关 SQS 的更多信息,请查看 this AWS 提供的详细 PDF

在处理消息时,实际上可以使用 ChangeMes​​sageVisibility() 。这允许您在向上或向下按住消息的同时更改超时时间。例如,如果您知道您的消息第一次失败,您可以将它设置为 0,它会将它放回队列中。如果您想要特别长的超时,您可以检查该类型的消息并将其设置为 10 分钟,例如。