Reputation: 755
I'm writing a script to limit/control the number of messages for each queue when it reached a certain threshold. I want to read how many available messages in the queue before adding more messages to it.
Example: Users will receive an error message to try again in few minutes because server is busy processing message when queue is around 100 messages pending and it will accept message again when pending messages in the queue is below 30..
I was looking at the SQS PHP methods and I don not see any method to view the current size of the queue or the available messages for the workers - http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.Sqs.SqsClient.html
Is there any way to read the message available in a queue?
Upvotes: 4
Views: 3750
Reputation: 269081
Use client.getQueueAttributes('ApproximateNumberOfMessages')
BTW, the whole purpose of queueing is not to worry about how busy a machine happens to be -- simply add the messages to the queue and they'll get processed eventually. By all means warn the user that it might take a while, but that doesn't mean you shouldn't let them lodge their request.
If you get really big queues, consider adding more parallel processing power, such as adding additional EC2 instances via Auto Scaling.
Upvotes: 4