我的NodeJS rabbitmq工作者经常抛出如下的异常:
events.js:72
throw er; // Unhandled 'error' event
Error: PRECONDITION_FAILED - unknown delivery tag 3
at Queue._onMethod (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:1720:15)
at Queue.Channel._onChannelMethod (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:1365:14)
at Connection._onMethod (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:922:28)
at AMQPParser.parser.onMethod (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:797:12)
at AMQPParser._parseMethodFrame (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:442:10)
at frameEnd (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:187:16)
at frame (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:172:14)
at AMQPParser.header [as parse] (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:159:14)
at AMQPParser.execute (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:231:21)
at Connection.<anonymous> (/Users/Rana/WebstormProjects/TS/ts-worker/node_modules/amqp/amqp.js:837:12)
at Connection.emit (events.js:95:17)
at Connection.<anonymous> (_stream_readable.js:765:14)
at Connection.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Connection.Readable.push (_stream_readable.js:128:10)
我的工作人员代码如下所示:
connection.queue('task-queue-name', {autoDelete: false, durable: true}, function(queue){
queue.subscribe({ack: true, prefetchCount: 1}, function(params){
//custom code
queue.shift();
});
});
有没有人知道导致问题的原因可能是什么?感谢。
答案 0 :(得分:0)
至少有两个原因我可以想到为什么会发生这种情况:
queue.shift()
同一条消息您可以单独确认消息,而不是使用shift
:
queue.subscribe({ OPTS }, function (message, headers, deliveryInfo, messageObject) {
messageObject.acknowledge(false);
// or: messageObject.reject(true|false);
});