node-amqp icon indicating copy to clipboard operation
node-amqp copied to clipboard

basic.return get message which failed

Open funston opened this issue 10 years ago • 1 comments

reading the amqp doc, and looking at the code, delivering a mandatory:true message on a queue that has no consumer. is it to correct to assume the following (psuedo code):

msg_failed = false; exchange.on('basic.return',function(){ msg_failed = true; });

exchange.on("basic.ack',function(ack){ if (msg_failed === true){ sequence_number = args.deliveryTag.readUInt32BE(4); // this is the message sequence that failed });

success_seq = exchange.publish("happy_queue", {foo:'bar'}, {mandatory:true}).sequence; failed_seq = exchange.publish("sad_queue", {foo:'bar'}, {mandatory:true}).sequence;

i'm seeing this work, in general, but not under load, with millions of messages. the sequence that comes in the next ack after a basic.return is in fact a message that was delivered and consumed by the happy queue. thanks.

funston avatar May 09 '14 05:05 funston

this is an oversight in node-amqp I think, in this ruby lib the payload is available for example:

A returned message handler has access to AMQP method (basic.return) information, message metadata and payload (as a byte array). The metadata and message body are returned without modifications so that the application can store the message for later redelivery.

in exchange.js:179 the message should be retrieved just like in the basicAck branch above and passed on to the callback IMO. ~~I'm probably going to write a PR for this now.~~ EDIT: dropped the meteor package wrapping this lib and switched over to amqp.node which we are using in another codebase already.

s-ol avatar Apr 03 '17 14:04 s-ol