开发者

How to get precise number of messages in Amazon Simple Queue Service?

开发者 https://www.devze.com 2023-03-30 10:36 出处:网络
Currently, I am investigating the Amazon SQS. I am trying to get the number of messages in the queue.

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 开发者_如何学Cupdating 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号