Why can't I receive messages from my Amazon SQS queue?

4 minute read
0

I made the ReceiveMessage API call to my Amazon Simple Queue Service (Amazon SQS) queue, but no messages were returned.

Short description

After you use the SendMessage or SendMessageBatch API call to send messages to the Amazon SQS queue, the ReceiveMessage API call can retrieve them. When the ReceiveMessage API call doesn't find any messages in the queue, it returns an empty receive result.

Note: The MaxNumberOfMessages parameter specifies that the maximum number of messages that's returned is 10, and the default value is 1.

For more information, see Message lifecycle.

Resolution

Confirm that the message was sent

Use the Amazon CloudWatch NumberOfMessagesSent metric to check that the messages were sent to the Amazon SQS queue. You can use the Amazon SQS SendMessage or SendMessageBatch API actions to check for sent messages:

Check for message deduplication

Because Amazon SQS First-In-First-Out (FIFO) queues don't introduce duplicate messages, the queues might be deduped. Check the message deduplication to confirm that messages are sent within the 5-minute deduplication interval.

Check for message delays

Amazon SQS queues that you configure as delay queues are postponed for the duration of the delay period. Messages that you send with message timers aren't visible until the delay time ends.

To check whether you configured the queue with a delivery delay or a message timer, use the ApproximateNumberOfMessagesDelayed CloudWatch metric.

Check the polling mode

A message might get delivered to the SQS queue, but it's not available for polling. For more information on Amazon SQS polling, see Using the appropriate polling mode.

Short polling

Short polling responses are returned immediately, even if the query found no messages. Amazon SQS samples a subset of its servers and returns messages from only those servers. For more information, see Consuming messages using short polling.

Long polling

Long polling uses all of its servers to query messages. Amazon SQS sends a response after it collects at least one available message up to the maximum number that's specified. An empty response is returned only if the polling wait time expires. When a queue contains messages that specify a low value for ReceiveMessage wait time, you might receive empty responses. For more information, see Consuming messages using long polling.

Check if a message from the same group ID is in flight

A FIFO queue's message ordering is maintained at the message group level. Messages that are received with a message group ID don't return more messages for the same group ID unless you delete the message, or it becomes visible. A message might get delivered to the queue, but might not be available when it's in flight or invisible.

To check if the message for the group ID is in flight or invisible, use the NumberOfMessagesReceived or ApproximateNumberOfMessagesNotVisible CloudWatch metrics.

For more information, see Why doesn't my Amazon SQS FIFO queue return all messages or messages in other message groups?

Confirm that the message is available or visible

If a different consumer polled the message and the message is in flight or invisible, then additional polls might return an empty receive. To check if there are no available messages to receive, use the ApproximateNumberOfMessagesVisible or ApproximateNumberOfMessagesNotVisible CloudWatch metrics.

Check if the queue is empty

To determine if a queue is empty, use long polling to call the ReceiveMessage API. You can also use the ApproximateNumberOfMessagesVisible, ApproximateNumberOfMessagesNotVisible, and ApproximateNumberOfMessagesDelayed CloudWatch metrics. If all the metric values are set to 0 for several minutes, then the queue is empty.

For more information, see Confirming that a queue is empty.

Troubleshoot with AWS Support

If none of the preceding troubleshooting steps resolve the issue, then contact AWS Support. In your communication with AWS Support, include the message request's RequestId and timestamp with timezone.

Related information

How can I find out who consumed my Amazon SQS queue messages?

How can I prevent an increasing backlog of messages in my Amazon SQS queue?

Getting started with Amazon SQS FIFO queues

AWS OFFICIAL
AWS OFFICIALUpdated a year ago