【发布时间】:2013-12-12 17:35:24
【问题描述】:
我在节点应用程序中使用 node-amqp 作为排队系统。我希望能够监控队列的状态,以确定我们是否有足够的工作人员在运行,即队列大小是否在增加,我们知道我们开始落后了。
我知道从命令行你可以使用类似的东西;
rabbitmqctl list_queues
这为我提供了我需要的确切信息,但我想知道是否可以从 node-amqp 本身执行此操作?
提前致谢。
编辑
最后,我只是使用命令行工具rabbitmqctl来获取我需要的信息,这不是一个很好的解决方案,但这是我所做的;
var Logger = require('arsenic-logger');
getQueueMeta(function(info){
Logger.info(info);
});
/**
* Returns a sparse array with the queue names as the indices
* and the number of messages as the value, e.g.;
*
* info = [ my-queue: 9, my-other-queue: 1 ]
*
* @param callback
*/
function getQueueMeta(callback){
var sys = require('sys')
var exec = require('child_process').exec;
exec("/usr/local/sbin/rabbitmqctl list_queues", function(error, stdout, stderr) {
var info = [];
if (!error){
var lines = stdout.split(/\n/);
if (lines.length > 1){
for (var i=1; i<lines.length-2; i++){
var temp = lines[i].split(/\s/);
info[temp[0].trim()] = parseInt(temp[1]);
}
}
}
callback(info);
});
}
【问题讨论】: