Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of messages in an Amazon SQS Queue

Just a simple question, but I can't seen to find the answer.

Is it possible to use the API, to get the queue size (the number of messages/jobs waiting to be processed) of an AWS SQS queue?

Preferably using cURL or the PHP SDK.

like image 966
Martijn Thomas Avatar asked Aug 17 '14 16:08

Martijn Thomas


People also ask

What is number of messages received in SQS?

For a standard SQS queue, there is a limit of 120,000 inflight messages, and and 20,000 is the limit for FIFO queues. It's important to keep an eye on this limit because if you exceed it, you will be unable to process more messages until you reduce the number of inflight messages.

How do I view the SQS queue messages?

From the left navigation pane, choose Queues. From the queue list, select the queue that you created. From Actions, choose Send and receive messages. The console displays the Send and receive messages page.

How do you find metrics in SQS?

Amazon CloudWatch consoleSign in to the CloudWatch console . On the navigation panel, choose Metrics. Select the SQS metric namespace. Select the Queue Metrics metric dimension.

How many messages per second can SQS handle?

If you require higher throughput, you can enable high throughput mode for FIFO on the Amazon SQS console, which will support up to 30,000 messages per second with batching, or up to 3,000 messages per second without batching.


2 Answers

I believe what you are looking for is get-queue-attributes, perhaps interrogating the ApproximateNumberOfMessages attribute.

like image 193
dangerousdave Avatar answered Sep 20 '22 03:09

dangerousdave


You can retrieve Attributes of the Queue and look for the relevant properties (See this link). You might want to look at both the following attributes.

ApproximateNumberOfMessages - Returns the approximate number of visible messages in a queue

ApproximateNumberOfMessagesNotVisible - Returns the approximate number of messages that have not timed-out and aren't deleted.

If you want to include the messages that are waiting to be added, you can consider the following property as well.

ApproximateNumberOfMessagesDelayed - Returns the approximate number of messages that are waiting to be added to the queue.

Finally do a summation of the values returned by the above properties and get the size of the current queue.

like image 43
Keet Sugathadasa Avatar answered Sep 23 '22 03:09

Keet Sugathadasa