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?
Use a callback in the publish function. End the connection in the callback and exit.