Reputation: 383
Currently, I am investigating the Amazon SQS. I am trying to get the number of messages in the queue.
The way I did is to sum up the number of ApproximateNumberOfMessages and ApproximateNumberOfMessagesNotVisible (which I got from Queue Attributes).
However, there are delay of updating on Amazon sqs. For example, I will get 0 message in the queue if I just sent the message to the queue 5 seconds ago. I tried to wait for 1 minutes after sending the message to the queue. But, sometimes, it doesn't work.
So, I am wondering what the best way to capture this information. Thanks.
Upvotes: 5
Views: 3620
Reputation: 491
What you did was basically the only way of knowing that. SQS has eventual consistency which means its hard to get the exact real number.
For debugging purposes I suggest logging in the requests of adding to the queue and logging in the requests for pulling out of the queue.
You can also add some kind of a unique ID (or an incrementing ID) to each message so you can track it more easily.
Upvotes: 4