Skip to content
Browse files

comments

  • Loading branch information...
1 parent 4d90c71 commit c23948426489805960dda7270ffc2475bec93e71 @carlhoerberg carlhoerberg committed
Showing with 11 additions and 9 deletions.
  1. +11 −9 app.js
View
20 app.js
@@ -1,15 +1,17 @@
-var amqp = require('amqp');
+var amqp = require('amqp');
function pub_and_sub() {
- var exchange = conn.exchange('');
- var queue = conn.queue('queue1', {}, function() {
- queue.subscribe(function(msg) {
- console.log(msg.body);
+ var exchange = conn.exchange(''); // get the default exchange
+ var queue = conn.queue('queue1', {}, function() { // create a queue
+ queue.subscribe(function(msg) { // subscribe to that queue
+ console.log(msg.body); // print new messages to the console
});
- exchange.publish(queue.name, {body: 'Hello CloudAMQP!'});
+
+ // publish a message
+ exchange.publish(queue.name, {body: 'Hello CloudAMQP!'});
});
}
-var url = process.env.CLOUDAMQP_URL || "amqp://localhost";
-var conn = amqp.createConnection({url: url});
-conn.on('ready', pub_and_sub);
+var url = process.env.CLOUDAMQP_URL || "amqp://localhost"; // default to localhost
+var conn = amqp.createConnection({url: url}); // create the connection
+conn.on('ready', pub_and_sub); // when connected, call "pub_and_sub"

0 comments on commit c239484

Please sign in to comment.
Something went wrong with that request. Please try again.