I need to get the number of SQS messages available and messages in flight using aws-sdk with javascript. Can someone please give me some kind of reference or code snippet? I need metadata for this SQS. I can send Messages and read it but need this info to conclude if there is high load on my infrastructure
You can make use of GetQueueAttributes. As per your requirements, fetching only ApproximateNumberOfMessages, ApproximateNumberOfMessagesNotVisible, ApproximateNumberOfMessagesDelayed should suffice. You can read more about these parameters here.
Sample code to get you moving:
var params = {
QueueUrl: '<sqs_queue>',
AttributeNames: [
ApproximateNumberOfMessages,
ApproximateNumberOfMessagesNotVisible,
ApproximateNumberOfMessagesDelayed
]
};
sqs.getQueueAttributes(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});