Skip to content

Commit

Permalink
support listening to basic-return messages on an exchange with on('ba…
Browse files Browse the repository at this point in the history
…sic-return'...)
  • Loading branch information
postwait committed Sep 19, 2011
1 parent 81febcc commit f7ff76a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion amqp.js
Expand Up @@ -1815,7 +1815,7 @@ Exchange.prototype._onMethod = function (channel, method, args) {
break;

case methods.basicReturn:
sys.puts("Warning: Uncaught basicReturn: "+JSON.stringify(args));
this.emit('basic-return', args);
break;

default:
Expand Down
29 changes: 29 additions & 0 deletions test/test-basic-return.js
@@ -0,0 +1,29 @@
require('./harness');

var fire, fired = false,
replyCode = null,
replyText = null;

connection.addListener('ready', function () {
connection.exchange('node-simple-fanout', {type: 'fanout'},
function(exchange) {
exchange.on('basic-return', function(args) {
fired = true;
replyCode = args['replyCode'];
replyText = args['replyText'];
clearTimeout(fire);
followup();
});
exchange.publish("", "hello", { mandatory: true, immediate: true });
});
});

function followup() {
assert.ok(fired);
assert.ok(replyCode === 312);
assert.ok(replyText === "NO_ROUTE");
connection.end();
}
fire = setTimeout(function() {
followup();
}, 5000);

0 comments on commit f7ff76a

Please sign in to comment.