Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all messages in SQS queue using AWS SDK for PHP

I am trying to retrieve all the messages in the queue using the AWS PHP SDK.

Earlier there used to be a get_queue_size() method to get the queue size and then I would iterate through the loop to get all the messages.

In the newest SDK I don't see such a method. Link

Can someone tell me how I can receive all the messages in the queue using the latest SDK for PHP ?

like image 346
Viraj Avatar asked Nov 23 '25 01:11

Viraj


1 Answers

You can get all the messages in the queue, you just can't get them all at once. You request messages, and specify the max you want up to a max of 10 at a time, anymore than that, and you'll need to request another set of messages until your queue is empty (and even then you need to constantly poll SQS if there is a possibility that new messages will be coming in at anytime).

Also important to remember that even if you have less than 10 messages in the queue, and you request the max of 10 (and even if there are no other clients currently polling), you still may not get all of the messages in the queue on a given call - you need to poll repeatedly.

like image 85
E.J. Brennan Avatar answered Nov 25 '25 14:11

E.J. Brennan