vendredi 27 février 2015

Amqp, RabbitMQ and NodeJS

I m actually trying to use RabbitMQ through AMQP with NodeJS to manage an online/offline message queue.


I have reproduced the tutorial code, having now :



var amqp = require('amqp');

var connection = amqp.createConnection({ host: 'http://127.0.0.1:5672/' });

// Wait for connection to become established.
connection.on('ready', function () {

var sendMessage = function (queue, msg) {
connection.publish(queue, JSON.stringify(msg));
}


connection.queue('my-queue', function (q) {
q.bind('#');

q.subscribe(function (message) {
console.log(JSON.parse(message.data));
});


sendMessage('my-queue', 'tototototo');

});

})


It works great. Now, I have two questions :



  • Can I respond to a particulier client that sent a message ?

  • How can I know if every client has got all the messages in the queue before using ack() ?


Thanks for advance


Aucun commentaire:

Enregistrer un commentaire