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

publish() not calling callback during/after reconnect

Open tcort opened this issue 11 years ago • 7 comments

I have some code that looks something like this. It publishes 1 message per second. It waits until the prior message has been published before publishing a new message.

(function sendMessage() {
        var msg = msgs.shift();

        console.log('Sending %d', msg.id);
        exchange.publish(routingKey, msg, options, function (err) {
                if (err) {
                        console.log('Failed to send %d, requeueing', msg.id);
                        msgs.unshift(msg);
                } else {
                        console.log('Sent %d', msg.id);
                }
                setTimeout(sendMessage, 1000);
        });
})();

The exchange is durable, non-autoDelete, topic type with confirm turned on. When I run the above code and I send while the connection is down, I never get a callback.

Connected
Sending 0
Sent 0
Sending 1
Sent 1
Error: CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', will retry
Error: connect ECONNREFUSED
Sending 2
Error: connect ECONNREFUSED
Error: connect ECONNREFUSED
Error: connect ECONNREFUSED
Connected

I am expecting the callback to be called when the connection is reestablished and the message is sent -- either that or I would expect a publication error (because the connection is down). Instead, there is no callback. With the debugging output turned on, I see that it does a basicPublish and gets a basicAck after the reconnect, but the callback isn't called.

Environments:

  • FreeBSD 8.1 / RabbitMQ v3.3.1 / node v0.10.28
  • Mac OS X 10.10.1 / RabbitMQ v3.4.1 / node v0.10.32

tcort avatar Jan 06 '15 14:01 tcort

the same problem, I wish to be notified if I pubilish a message when connection is broken. Instead, connection.on('error') seems to catch the problem, but, how could I know which message is not sent. Or, can publish task restarted after connection reestablished?

YEXINGZHE54 avatar Feb 07 '15 10:02 YEXINGZHE54

Same issue. Looking forward to having it fixed. I would expect that if connection is closed (as close event notifies), publish method's callback is called with err set to true. Or at least, being able to check connection status.

eguzki avatar Feb 10 '15 17:02 eguzki

This is solved on https://github.com/dropbox/amqp-coffee which is based off node-amqp but has a slightly different api

barshow avatar Feb 10 '15 18:02 barshow

+1

andre1810 avatar May 13 '15 09:05 andre1810

And me too! Somebody, are you here? We all need help about this issue :)

iBorodai avatar May 20 '15 09:05 iBorodai

@tcort in your case, you should pass "confirm" option while declaring exchange https://github.com/postwait/node-amqp#exchange so, somthing like this:

connection.exchange( '< someName> ', { autoDelete:false, ... , confirm:true }, function onExchange(){...} );

I think, it should hуlp:)

iBorodai avatar May 20 '15 10:05 iBorodai

+1

skysteve avatar Jul 22 '15 08:07 skysteve