Skip to content
Browse files

Synchronise with an RPC after sending a message

Closing the connection can have the effect of abandoning frames that
haven't been written yet. This is noticable with recent versions of
when.js (v2.5.1 say) which will run the thunk given to `.ensure`,
thereby closing the connection, before the publish has been written to
the socket.
  • Loading branch information...
1 parent 06411eb commit 36592842fcdcb70c3d34248c5997dbe03203ef62 @squaremo committed
View
1 examples/tutorials/emit_log.js
@@ -14,6 +14,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ok.then(function() {
ch.publish(ex, '', new Buffer(message));
console.log(" [x] Sent '%s'", message);
+ return ch.close();
});
})).ensure(function() { conn.close(); });
}).then(null, console.warn);
View
1 examples/tutorials/emit_log_direct.js
@@ -15,6 +15,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ok.then(function() {
ch.publish(ex, severity, new Buffer(message));
console.log(" [x] Sent %s:'%s'", severity, message);
+ return ch.close();
});
})).ensure(function() { conn.close(); });
}).then(null, console.warn);
View
1 examples/tutorials/emit_log_topic.js
@@ -14,6 +14,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ok.then(function() {
ch.publish(ex, key, new Buffer(message));
console.log(" [x] Sent %s:'%s'", key, message);
+ return ch.close();
});
})).ensure(function() { conn.close(); })
}).then(null, console.log);
View
1 examples/tutorials/new_task.js
@@ -13,6 +13,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
var msg = process.argv.slice(2).join(' ') || "Hello World!"
ch.sendToQueue(q, new Buffer(msg), {deliveryMode: true});
console.log(" [x] Sent '%s'", msg);
+ return ch.close();
});
})).ensure(function() { conn.close(); });
}).then(null, console.warn);
View
1 examples/tutorials/send.js
@@ -13,6 +13,7 @@ amqp.connect('amqp://localhost').then(function(conn) {
return ok.then(function(_qok) {
ch.sendToQueue(q, new Buffer(msg));
console.log(" [x] Sent '%s'", msg);
+ return ch.close();
});
})).ensure(function() { conn.close(); });;
}).then(null, console.warn);

0 comments on commit 3659284

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