Created
October 23, 2013 07:55
-
-
Save paulja/7114328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------------------------- | |
// 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