Can't see/receive all messages from AWS SQS

Viewed 5033

I have a FIFO SQS queue, and I am sending 4 messages one after another. 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.

I've sent 4 more messages - now I had 8 messages total. 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.

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.

enter image description here

What am I doing wrong that I can see all available messages?

2 Answers

You need to delete the message with the ReceiptHandle to get the other messages. FIFO queues guarantee ordering inside a message group and a message is not delivered until previous messages are processed. 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.

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. 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.

See: Amazon SQS FIFO (First-In-First-Out) queues - Amazon Simple Queue Service

Related