publish() not calling callback during/after reconnect
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
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?
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.
This is solved on https://github.com/dropbox/amqp-coffee which is based off node-amqp but has a slightly different api
+1
And me too! Somebody, are you here? We all need help about this issue :)
@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:)
+1