Skip to content

Instantly share code, notes, and snippets.

@paulja
Created October 23, 2013 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulja/7114328 to your computer and use it in GitHub Desktop.
Save paulja/7114328 to your computer and use it in GitHub Desktop.
// -----------------------------------------------
// AMQP Acknowledgement Sample
//
// Paul Jackson (https://medium.com/@pj_)
var amqp = require('amqp');
// Make a connection
var connection = amqp.createConnection();
// Report errors
connection.on('error', function(e) {
throw e;
});
// When the connection is ready
connection.on('ready', function() {
// Create | Connection to an exchange
connection.exchange('acks-ex', { confirm: true }, function(ex) {
// Create | Connection to a queue
connection.queue('spike', function(q) {
q.bind(ex.name, q.name);
// Subscribe for messages
q.subscribe(function(message) {
console.log('> Received: ', message.data.toString());
});
// Publish message
ex.publish('spike', 'hello', { deliveryMode: 2 }, function() {
// ACK
connection.end(); // <-- end
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment