我的代码如下所示:
scheduler.js
const callMethodForeverRabbitMq = () => {
cron.schedule('*/1 * * * * *', function () {
console.log('rabbitmq is calling');
rabbitMqClientPipeline.subscribeWalletChannel((err, data) => {
console.log('rabbitmq subscribe called');
if (!err) {
console.log('message is ' + data);
}
})
});
};
rabbitmq.js
const subscribeWalletChannel = (cb) => {
console.log('subscribe method called');
client.subscribe('channel_name', function () {
client.on('message', function (topic, message, packet) {
console.log("Received '" + message + "' on '" + topic + "'");
return cb(null, message);
});
});
}
运行此代码后,它会警告我:
0|app | (node:8973) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit