Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ: Relationship between channels and exchanges

Right now I'm using rabbitMQ to send data between two programs - 1 queue, 1 channel, 1 exchange. I'm going to extend it to be multithreaded and I want to declare another queue on the second thread.

  • I understand in this case I should use another channel, but what I would like to know is is it necessary to declare another exchange with a different name as well?
  • What exactly is the relationship between the two?
  • In what kind of situation would you need multiple exchanges?
like image 574
yakka Avatar asked Oct 28 '25 08:10

yakka


2 Answers

As you figured out, the channel is the communication end point used to reach a rabbitMQ object.

There are so far 2 kinds of objects:

  • Queues, which are simply buffers for messages,
  • Exchanges, which are broadcasting devices.

As a simple analogy, queues are the pipes in which messages get accumulated, and exchanges are the T shaped, cross shaped and other types of connectors between pipes.

Perhaps it works better to compare it with a physical network, where queues would be like cables, and exchanges like switches or smart hubs, for which different distribution strategies can be chosen.

So basically, what you need to do is simply create a new queue from the new consumer thread, have it connect to the exchange object (for which you should have a name), and let the producer thread send its messages to the exchange object exclusively. Any new thread may follow the same protocol.

The last important point is to pick the correct distribution method for the exchange object, round-robin, fanout, etc. depending on how you wish your consumers to receive messages.

like image 81
didierc Avatar answered Oct 30 '25 12:10

didierc


Take a look at our introduction to AMQP concepts

http://www.rabbitmq.com/tutorials/amqp-concepts.html

like image 38
old_sound Avatar answered Oct 30 '25 10:10

old_sound