1

我在 Node.js 中收到以下错误,我认为它与 AMQP 有关。

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Connection.EventEmitter.addListener (events.js:160:15)
    at Connection.EventEmitter.once (events.js:179:8)
    at Connection.connect (/var/www/project/app/node_modules/amqp/amqp.js:1084:8)
    at Connection.reconnect (/var/www/project/app/node_modules/amqp/amqp.js:1049:8)
    at null._onTimeout (/var/www/project/app/node_modules/amqp/amqp.js:886:16)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

谁能指出问题可能是什么?

这是我用来连接的模块中的代码:

JackRabbit.prototype.subscribe = function subscribe(recievedCB, routingKey) {
    var self = this;
    var route = routingKey || '#';

    self.createConnection(function(rabbitMq, ex, q) {
        // Catch all messages
        q.bind(self.config.exchangeName, route);

        // Receive messages
        q.subscribe(self.config.messageOptions, function(msg, headers, deliveryInfo) {            
            recievedCB(q, msg, headers, deliveryInfo);

            // Clsoe connection
            //rabbitMq.end();
        });        
    });
}

这里是我调用该方法的地方:

var scrapRequestRecieved = function(q, msg, headers, deliveryInfo) {
    console.log("SC msg: %j", msg);

    /** Callback function shifts the completed job from the queue. */
    phantom.scrapeUrls(msg.urls, function() {
        console.log("SC DONE");
        q.shift();
    });
};
rabbit.subscribe(scrapRequestRecieved, "sc.#");
4

2 回答 2

2

经过一番搜索,问题似乎是由 AMPQ 的旧连接逻辑引起的。每次尝试重新连接时,都会添加一个新的侦听器,而不会删除旧的侦听器。该问题已在拉取请求中得到修复。

于 2013-09-13T16:13:27.297 回答
1

最新版本0.1.8包含了 @hexacyanide 注释的拉取请求。

于 2013-12-18T13:16:22.660 回答