我需要使用aws-sdk和javascript来获取可用的SQS消息和正在传输的消息的数量。有人能给我一些参考或代码片段吗?我需要这个SQS的元数据。我可以发送消息并阅读它,但需要此信息来推断我的基础架构上是否存在高负载
发布于 2021-09-09 06:18:10
您可以使用GetQueueAttributes。根据您的需求,只需获取ApproximateNumberOfMessages
、ApproximateNumberOfMessagesNotVisible
、ApproximateNumberOfMessagesDelayed
就足够了。您可以阅读有关这些参数的更多信息here。
让您行动起来的示例代码:
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);
});
https://stackoverflow.com/questions/69112861
复制相似问题