jeudi 26 février 2015

How to consume just one message from rabbit mq on nodejs

Im using amqp.node library to integrate rabbitmq into my system.


But in consumer i want to process just one message at the time, then acknowledge the message then consume the next message from the queue.


The current code is:



// 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);


The ch.consume will process all messages in the channel at one time and the function of the module call it here othermodule will not be executed in the same time line.


I want to wait for the othermodule function to finish before consume the next message in the queue.


Aucun commentaire:

Enregistrer un commentaire