【发布时间】:2015-02-26 16:06:46
【问题描述】:
我正在使用 amqp.node 库将 rabbitmq 集成到我的系统中。
但在消费者中,我想一次只处理一条消息,然后确认该消息,然后使用队列中的下一条消息。
目前的代码是:
// Consumer
open.then(function(conn) {
var ok = conn.createChannel();
ok = ok.then(function(ch) {
ch.assertQueue(q);
ch.consume(q, function(msg) {
if (msg !== null) {
othermodule.processMessage(msg, function(error, response){
console.log(msg.content.toString());
ch.ack(msg);
});
}
});
});
return ok;
}).then(null, console.warn);
ch.consume 将一次性处理通道中的所有消息,并且此处调用它的模块的功能将不会在同一时间线执行。
我想在消费队列中的下一条消息之前等待 othermodule 函数完成。
【问题讨论】: