Do I need rabbitmq bindings for direct exchange?

Question:

I have a rabbit mq server running, with one direct exchange which all my messages go through. The messages are routed to individual non-permanent queues (they may last a couple hours). I just started reading about queue bindings to exchanges and am a bit confused as to if I actually need to bind my queues to the exchange or not. I’m using pika basic_publish and consume functions so maybe this is implied? Not really sure just wanna understand a bit more.

Thanks

Asked By: tuck

||

Answers:

Always. In fact, even though queues are strictly a consumer-side entity, they should be declared & bound to the direct exchange by the producer(s) at the time they create the exchange.

Answered By: pbhowmick

You have to bind a queue with some binding key to an exchange, else messages will be discarded.

This is how any amqp broker works, publisher publish a message to exchange with some key, amqp broker(RabbitMq) routes this message from exchange to those queue(s) which are binded with exchange with the given key.

However it’s not mandatory to declare and bind a queue in publisher.
You can do that in subscriber but make sure you run your subscriber before starting your publisher.

If you think your messages are getting routed to queue without bindings than you are missing something.

Answered By: mannuscript

If you are using the default exchange for direct routing (exchange = ”), then you don’t have to declare any bindings. By default, all queues are bound to the default exchange. As long as the routing key exactly matches a queue name (and the queue exists), the queues can stay bound to the default exchange. See https://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html.

Answered By: Shamiul
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.