Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SQS ReceiveMessage receiving less / fewer messages than requested?

I have a simple SQS configured, and I want to process 4 messages at a time. In my test, It has 2 "available" messages. When I get the message, it results in only 1 at a time. What am I doing wrong?

Queue general configuration

sqs list

sqs = boto3.client('sqs')
response = sqs.receive_message(
    QueueUrl=queue_url,
    MaxNumberOfMessages=4
)
like image 433
Lücks Avatar asked Dec 13 '25 03:12

Lücks


1 Answers

You are not doing anything wrong, the behaviour is expected.

That is due to the distributed nature of SQS (and most AWS services). Basically not all nodes have all messages available and the node you talk to may return any number between 0 and MaxNumberOfMessages if any are available. To actually receive multiple message in a single call you need to have 100s or 1000+s of messages in the queue and even then you can be unlucky and receive very few messages.

From the docs:

If the number of messages in the queue is small (fewer than 1,000), you most likely get fewer messages than you requested per ReceiveMessage call. If the number of messages in the queue is extremely small, you might not receive any messages in a particular ReceiveMessage response. If this happens, repeat the request.

like image 162
luk2302 Avatar answered Dec 14 '25 17:12

luk2302



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!