1

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

tuck
  • 452
  • 5
  • 15

3 Answers3

4

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.

TarHalda
  • 1,050
  • 1
  • 9
  • 27
Shamiul
  • 41
  • 2
1

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.

pbhowmick
  • 1,093
  • 11
  • 26
  • 1
    it seems to work without bindings though, don't see any problems yet. Any thing I will run into in the future? – tuck Jan 15 '16 at 18:24
  • It boils down to a best practice. This is not limited to just direct exchanges. – pbhowmick Jan 18 '16 at 21:16
  • Suppose the publisher starts publishing before any consumers come online and declare & bind queues to that exchange. In that case, the messages may be discarded or DLOed. – pbhowmick Jan 18 '16 at 21:17
1

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.

mannuscript
  • 4,711
  • 6
  • 26
  • 25