4

I am using RabbitMQ in my project and was wondering if I should use a single exchange with multiple routing keys or use multiple exchanges? Which would be more efficient?

Example if I use single exchange E with routing keys A,B,C and consumer connects to that exchange E and get data using A,B,C routing keys. Another option would be that I should send it to the exchange A, exchange B, exchange C with no routing keys and consumer could connect to each of the exchange for required data.

an example with python's library pika(which i am currently using):

channel.basic_publish(exchange='E',
                      routing_key='A',
                      body=data)  
channel.basic_publish(exchange='E',
                      routing_key='B',
                      body=data)  
channel.basic_publish(exchange='E',
                      routing_key='C',
                      body=data)

OR

channel.basic_publish(exchange='A',
                      routing_key='',
                      body=data)  
channel.basic_publish(exchange='B',
                      routing_key='',
                      body=data)  
channel.basic_publish(exchange='C',
                      routing_key='',
                      body=data)
Tushar Seth
  • 563
  • 7
  • 15

1 Answers1

0

You can go on your first approach. Declare your exchange as a Direct Exchange. In the case of a Direct Exchange, it takes the queue name as the routing key. An exchange is capable of binding itself to multiple queues. Also, the job of an exchange is to route the message to a queue. Having multiple queues bound to it will not decrease the efficiency of RabbitMQ.

bumblebee
  • 1,811
  • 12
  • 19