简体   繁体   English

无法看到/接收来自 AWS SQS 的所有消息

[英]Can't see/receive all messages from AWS SQS

I have a FIFO SQS queue, and I am sending 4 messages one after another.我有一个 FIFO SQS 队列,我正在一个接一个地发送 4 条消息。 After sending first 4 messages, I ran a program to receive them, but only 2 messages were returned - even with long polling and the max messages = 10.发送前 4 条消息后,我运行了一个程序来接收它们,但只返回了 2 条消息——即使轮询时间很长,最大消息数 = 10。

I've sent 4 more messages - now I had 8 messages total.我又发送了 4 条消息 - 现在我总共有 8 条消息。 Both the AWS SQS UI for receiving messages, and my code for receiving messages - showed only 2 messages, but said that 8 messages were available.用于接收消息的 AWS SQS UI 和我用于接收消息的代码 - 仅显示 2 条消息,但表示有 8 条消息可用。

After sending 4 more messages, you can see in the attached screenshot that SQS UI shows 12 messages available, but lists only 2 messages, and I have C# code to receive messages, with long-polling, that also returns only 2 messages.再发送 4 条消息后,您可以在附加的屏幕截图中看到 SQS UI 显示 12 条可用消息,但仅列出 2 条消息,并且我有 C# 代码来接收消息,使用长轮询,也仅返回 2 条消息。

在此处输入图片说明

What am I doing wrong that I can see all available messages?我做错了什么,我可以看到所有可用的消息?

You need to delete the message with the ReceiptHandle to get the other messages.您需要使用 ReceiptHandle 删除消息以获取其他消息。 FIFO queues guarantee ordering inside a message group and a message is not delivered until previous messages are processed. FIFO 队列保证消息组内的排序,并且在处理之前的消息之前不会传递消息。 You are seeing only some messages but not others because they are the first in the queue for their message groups.您只看到一些消息,而看不到其他消息,因为它们是消息组队列中的第一个。

I've encountered it a while back and blogged about how it works. 不久前我遇到过它,并在博客中介绍了它如何工作的。

You have select to use a First-In First-Out (FIFO) queue.您必须选择使用先进先出 (FIFO) 队列。

To ensure that messages are processed in the correct order, it is not possible to retrieve messages with the same Message Group ID if there are currently messages with that ID being processed.为确保以正确的顺序处理消息如果当前正在处理具有该 ID 的消息,则无法检索具有相同消息组 ID 的消息。 Otherwise, there is a risk that a message might be processed out-of-order.否则,消息可能会被乱序处理。

This is why your request for more messages is not providing back any messages.这就是为什么您对更多消息的请求不提供任何消息的原因。

If you simply want the messages to be in FIFO order without specific ordering within message groups, it is recommended that you provide a random Message Group ID so that each message can be processed individually.如果您只是希望消息按 FIFO 顺序排列,而没有在消息组内进行特定排序,建议您提供一个随机消息组 ID,以便可以单独处理每条消息。

See: Amazon SQS FIFO (First-In-First-Out) queues - Amazon Simple Queue Service请参阅: Amazon SQS FIFO(先进先出)队列 - Amazon Simple Queue Service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM