By default, the consume() function consumes all the messages that are in the queue, but I need pop only one message from the queue, and with the next consume() call pop the second message from the queue, etc. I have this code:
rabbit.js (in this file I have implemented the sending to and receiving from the queue):
var amqp = require('amqplib/callback_api');
var ch;
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, channel) {
ch = channel;
});
});
module.exports.queueSend = function(msg) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
ch.sendToQueue(q, new Buffer(msg));
console.log(" [x] Sent %s", msg);
}
module.exports.queueReceive = function() {
var q = 'hello';
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) {
console.log(" [x] Received %s", msg.content.toString());
}, {noAck: false});
}
rabbit_test.js (in this file I have tested the functionality of the previous code):
var rabbit = require("./rabbit");
setTimeout(function() {
rabbit.queueSend("01C");
rabbit.queueSend("02C");
rabbit.queueReceive();
}, 2000);
When I call the queueReceive() function, it prints out the "01C" and "02C" messages too, not only the "01C". I need print out only the "01C" and with a next queueReceive() call the "02C".
P.S.: I tried this code too in rabbit.js for function queueReceive():
module.exports.queueReceive = function() {
var q = 'hello';
ch.prefetch(1);
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) {
ch.ack(msg);
console.log(" [x] Received %s", msg.content.toString());
}, {noAck: false});
}
I added the ch.ack(msg) and ch.prefetch(1) parts, but it doesn't works neither.
How can i get this working? Thank you in advance!
By default, the consume() function consumes all the messages that are in the queue, but I need pop only one message from the queue, and with the next consume() call pop the second message from the queue, etc. I have this code:
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.