Search code examples
amazon-web-servicesamazon-sqs

AWS SQS Receive Messages -- How to Know when Queue is Empty


I want to get all the messages in the queue to process them. However the property for MaxNumberOfMessages is 10 (based on documentation)

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html

How can I read in all messages so I can process them? Or how would I know when queue is empty?

thanks


Solution

  • When you receive messages from the queue, they are marked as "in flight." After you successfully process them, you send a call to the queue to delete them. This call will include IDs of each of the messages.

    When the queue is empty, the next read will have an empty Messages array.

    Usually when I do this I wrap my call to read the queue in a loop (a while loop) and only keep processing if I have Messages after doing a read.

    It shouldn't make any difference if it's a FIFO queue or a standard one.