node-amqp
node-amqp copied to clipboard
auto create many connection
hi, i have some issue, i create a connection and then listen a queue to do some operation. But after the program run a month, i found that there are more than 20000 connection exist, what's wrong i did, my code is just like:
var conn = amqp.createConnection({url: 'amqp://'+config.rmqUser+':'+config.rmqPsw+'@'+config.rmqHost+':'+config.rmqPort});
conn.on('ready', function() {
conn.queue(config.rmqSellerInquiry, {durable:true, autoDelete:false}, function(queue) {
logger.log('RabbitMq connected with url: '+config.rmqHost+':'+config.rmqPort+' queue:'+config.rmqSellerInquiry);
queue.subscribe({ack:true, prefetchCount:1}, function(msg, header, deliveyInfo, ack) {
if (msg.data) {
var emailSendingInfo = JSON.parse(msg.data.toString());
emailSendingInfo.retryTimes = emailSendingInfo.retryTimes ? emailSendingInfo.retryTimes : 0;
emailSendingInfo.mqQueue = config.rmqSellerInquiry;
// logger.log(emailSendingInfo);
// ack.acknowledge();
mailClient.sendMail(emailSendingInfo, function(resMsg) {
if (resMsg.indexOf('Send Error') >= 0) {
if (resMsg.indexOf('MAIL_SENDER_ERROR') >= 0) {
setTimeout(function() {ack.reject(true); return;}, 1000*3);
}
else {
logger.log('=================================sendMail['+emailSendingInfo.emailId+'] send fail. acknowledge to queue.');
setTimeout(function() {ack.acknowledge(); return;}, 1000*3);
}
}
else {
logger.log('=================================sendMail['+emailSendingInfo.emailId+'] finish. It retried '+emailSendingInfo.retryTimes+' times');
setTimeout(function() {ack.acknowledge(); return;}, 1000*3);
}
});
}
});
});
});
Do you have anywhere in your code beside above to create connection? (for example, create a new connection anytime you publish a message to queue)