Permalink
Browse files

Be consistent with the original tutorials in console messages

Also: only try the one time to close the connection on SIGINT
  • Loading branch information...
1 parent 2bb66e1 commit 2b1acaefc4b522e5a2781fb6d24904635d4a8c6f @squaremo committed Jun 21, 2013
@@ -11,7 +11,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
ok = ok.then(function() {
ch.publish('logs', '', new Buffer(message));
- console.log(' [x] Sent %s', message);
+ console.log(" [x] Sent '%s'", message);
});
return ok.then(function() { conn.close(); });
});
@@ -11,7 +11,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
var msg = process.argv.slice(2).join(' ') || "Hello World!"
ch.sendToQueue('task_queue', new Buffer(msg),
{deliveryMode: true});
- console.log("[x] Sent '%s'", msg);
+ console.log(" [x] Sent '%s'", msg);
});
return ok;
}).then(function() { conn.close(); });
@@ -3,19 +3,19 @@
var amqp = require('amqplib');
amqp.connect('amqp://localhost').then(function(conn) {
- process.on('SIGINT', function() { conn.close(); });
+ process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {
var ok = ch.assertQueue('hello', {durable: false});
ok = ok.then(function(_qok) {
return ch.consume('hello', function(msg) {
- console.log("[x] Received '%s'", msg.content.toString());
+ console.log(" [x] Received '%s'", msg.content.toString());
}, {noAck: true});
});
return ok.then(function(_consumeOk) {
- console.log('[*] Waiting for messages. To exit press CTRL+C');
+ console.log(' [*] Waiting for messages. To exit press CTRL+C');
});
});
}).then(null, console.warn);
@@ -3,7 +3,7 @@
var amqp = require('amqplib');
amqp.connect('amqp://localhost').then(function(conn) {
- process.on('SIGINT', function() { conn.close(); });
+ process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {
var ok = ch.assertExchange('logs', 'fanout', {durable: false});
ok = ok.then(function() {
@@ -18,11 +18,11 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ch.consume(queue, logMessage, {noAck: true});
});
return ok.then(function() {
- console.log('[*] Waiting for logs. To exit press CTRL+C');
+ console.log(' [*] Waiting for logs. To exit press CTRL+C');
});
function logMessage(msg) {
- console.log(' [x] %s', msg.content.toString());
+ console.log(" [x] '%s'", msg.content.toString());
}
});
}).then(null, console.warn);
@@ -10,7 +10,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ok.then(function(_qok) {
ch.sendToQueue('hello', new Buffer(msg));
- console.log("[x] Sent '%s'", msg);
+ console.log(" [x] Sent '%s'", msg);
}).then(function() { conn.close(); });
});
}).then(null, console.warn);
@@ -4,23 +4,23 @@
var amqp = require('amqplib');
amqp.connect('amqp://localhost').then(function(conn) {
- conn.on('SIGINT', function() { conn.close(); });
+ conn.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {
var ok = ch.assertQueue('task_queue', {durable: true});
ok = ok.then(function() { ch.prefetch(1); });
ok = ok.then(function() {
ch.consume('task_queue', doWork, {noAck: false});
- console.log("[*] Waiting for messages. To exit press CTRL+C");
+ console.log(" [*] Waiting for messages. To exit press CTRL+C");
});
return ok;
function doWork(msg) {
var body = msg.content.toString();
- console.log("[x] Received '%s'", body);
+ console.log(" [x] Received '%s'", body);
var secs = body.split('.').length - 1;
- console.log("[x] Task takes %d seconds", secs);
+ //console.log(" [x] Task takes %d seconds", secs);
setTimeout(function() {
- console.log("[x] Done");
+ console.log(" [x] Done");
ch.ack(msg);
}, secs * 1000);
}

0 comments on commit 2b1acae

Please sign in to comment.