Skip to content

Instantly share code, notes, and snippets.

@duncanfinney
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save duncanfinney/661f010a5d926f105005 to your computer and use it in GitHub Desktop.

Select an option

Save duncanfinney/661f010a5d926f105005 to your computer and use it in GitHub Desktop.
AMQP Node.js Example
var amqp = require('amqp');
var connection = amqp.createConnection({
host: '192.168.64.10',
port: 5672
});
// Wait for connection to become established.
connection.on('ready', function () {
console.log('ready');
// Use the default 'amq.topic' exchange
connection.queue('my-queue', function (q) {
// Catch all messages
q.bind('#');
// Receive messages
q.subscribe(function (message) {
// Print messages to stdout
console.log('got a message: ', message);
});
q.subscribe(function(message) {
console.log('got a message 2: ', message);
})
connection.publish('my-queue', { hello: 'world' });
connection.publish('my-queue', { hello: 'world' });
connection.publish('my-queue', { hello: 'world' });
connection.publish('my-queue', { hello: 'world' });
connection.publish('my-queue', { hello: 'world' });
connection.publish('my-queue', { hello: 'world' });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment