5

Is there any difference between using the default (direct) exchange than creating a custom direct exchange for each queue?

(default exchange) -> queue1
(default exchange) -> queue2

vs.

queue1_direct_exchange -> queue1
queue2_direct_exchange -> queue2

In the RabbitMQ dashboard I can see that if I use the default exchange for every queue it has more messages rate so I'm wondering if using different exchanges would increase the performance of message dispatching...

Thanks in advance!

Ivan Guardado
  • 517
  • 3
  • 15
  • I am speculating here but when using direct exchange you need to check if the message has the correct key and route it accordingly so you have some overhead right there. But when you use default exchange it's just dumb broadcast and therefore faster. – cen Feb 10 '16 at 12:01
  • this is a close enough to a duplicate of http://stackoverflow.com/questions/33622667/why-shouldnt-i-use-rabbitmq-topic-exchanges-for-everything that i would rather just point you to my answer, there – Derick Bailey Feb 10 '16 at 12:59
  • Thanks @DerickBailey but I think my question is not answered and I think it's not duplicated. My question it is more about performance... Is it better to distribute the messages through different exchanges in terms of performance? – Ivan Guardado Feb 12 '16 at 14:36
  • ah, sorry - didn't see the bit about performance previously... added an answer below – Derick Bailey Feb 12 '16 at 15:31

1 Answers1

6

There is no significant performance improvement in using the default direct exchange vs other exchange types, off-hand. The performance differences that you will see depend on how much memory you have on the server, how many queues are receiving a single message, whether or not you are persisting messages to disk, and other factors.

In general, using the default direct exchange should be avoided. It sounds easy off-hand, but you end up with the design of your queueing system set up backwards, where the message publisher knows which queue should receive the message.

This is a mistake I made when I first started working with RabbitMQ and it ended up confusing me and causing problems. I didn't know why i needed an exchange, or what the purpose of the routing key was.

I wrote more about this, here: http://derickbailey.com/2014/11/14/understanding-the-relationship-between-rabbitmq-exchanges-queues-and-bindings/

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
  • 3
    thanks for sharing, good read. However I disagree with the approach of declaring queue within subscriber simply for the fact that if you publish to an exchange without a queue bind, then the messages are lost. I think in your analogy it would be like sending a post to the post office without an address written on it. Additionally, most of the time the producer & consumer are 2 separate processes. Unless you can guarantee the consumer starts first (to ensure there exists a queue bound to the exchange), then you should bind queue to exchange in producer to ensure no message lost. – yonasstephen Jun 30 '20 at 02:19