jens_h
jens_h

Reputation: 387

RabbitMQ: Message acked by exchange without any existing bindings to it

I´m sending a message to a topic exchange which hasn´t any bindings to any queues. Just a blank exchange. The channel is created as confirm channel and my confirm callback is called each time I send a message. The strange thing is that for each message I get ack.

Am I doing something wrong or missunderstand the way how publisher confirmation works? How can I know if a message is routed to a queue or dropped by the exchange?

I´m using amqplib for node.


Ok probably I didn´t explain my issue clear enough. So here is some code:

var amqp = require('amqplib/callback_api');
amqp.connect('amqp://host' , function(err, conn) {

    conn.createConfirmChannel(function(err, ch) {

        channel.assertExchange('my_awsome_exchange', 'topic', {durable: true});

        channel.publish('my_awsome_exchange', 'routing_key', new Buffer('some data'),
        {
            mandatory: true
        },
        function(err){
           // err is null no matter if a queue is bound to the exchange or not
           console.log(err);
        });
    });
});

As you can see an exchange is created but no queue is bound to this exchange yet. So my expectation was that sending messages to this exchange would never be acked. @Teddy: I know this section from the docs and this is the reason why I´m so confused. As the message isn´t routed to any queue I would have expected the message to be nacked.

Upvotes: 7

Views: 12095

Answers (3)

R Karwalkar
R Karwalkar

Reputation: 59

I have tried the channel.confirmSelect() and its doesnt garuntee that message sent to queue rather than it give guarantee that message published to exchange. If no queue is bound at that moment then RabbitMQ server will simply discard the message.

Upvotes: 1

Tolis Gerodimos
Tolis Gerodimos

Reputation: 4408

I believe the misunderstanding lies in the fact, that an "Ack" means that the server successfully routed the message.

But the previous statement is false. Ack actually means that the server was able to handle the message successfully.

You can think of it like the RabbitMQ server saying: I take responsibility for your message

"basic.nack will only be delivered if an internal error occurs in the Erlang process responsible for a queue."

Quoted by the following Link https://www.rabbitmq.com/confirms.html

Upvotes: 3

Teddy Ma
Teddy Ma

Reputation: 1136

It is by design. Check this link. It says clearly:

When will messages be confirmed?

For unroutable messages, the broker will issue a confirm once the exchange verifies a message won't route to any queue (returns an empty list of queues). If the message is also published as mandatory, the basic.return is sent to the client before basic.ack. The same is true for negative acknowledgements (basic.nack).

For routable messages, the basic.ack is sent when a message has been accepted by all the queues. For persistent messages routed to durable queues, this means persisting to disk. For mirrored queues, this means that all mirrors have accepted the message.

Upvotes: 13

Related Questions