Question

If I use the following code to send a message to RabbitMQ:

var amqp = require('amqp');
var connection = amqp.createConnection();
connection.on('ready', function() {
  connection.publish('foo', 'Hello');
  process.exit();
});

...then the message is never sent, and the process just quits. If I remove process.exit(), then the message is sent, but the process never quits.

How do I get node-amqp to tell me when it has sent a message?

Was it helpful?

Solution

Use a callback in the publish function. End the connection in the callback and exit.

connection.publish('foo', 'hello', function(){
   connection.end();
   process.exit();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top