RabbitMQ Exchanges

In rabbitmq, when producer creates a message that will not directly sent to a queue, instead first the message will be send to exchanges, then after that a routing agent reads and sends it to the appropriate queue with help of header attributes, bindings, and routing keys.

RabbitMQ Exchange Types

In rabbitmq, we have a four type of Exchanges are available to route the message in different ways.

 

Following are the different type of exchanges available in rabbitmq.

 

  • Direct
  • Fanout
  • Topic
  • Headers

RabbitMQ Direct Exchange

In rabbitmq, direct exchange will deliver a messages to the queues based on the message routing key. In direct exchange, the message is routed to the queues whose binding key exactly matches with the routing key of the message.

 

Following is the pictorial representation of message flow in rabbit direct exchange.

 

RabbitMQ Direct Exchange Process Flow Diagram

RabbitMQ Fanout Exchange

In rabbitmq, fanout exchange will route messages to all of the queues that are bound to it.

 

Following is the pictorial representation of message flow in rabbitmq fanout exchange.RabbitMQ Fanout Exchange Process Flow Diagram

RabbitMQ Topic Exchange

In rabbitmq, topic exchange will perform a wildcard match between the routing key and the routing pattern specified in the binding to publish a messages to queue.

 

Following is the pictorial representation of message flow in rabbitmq topic exchange.

 

RabbitMQ Topic Exchange Process Flow Diagram

RabbitMQ Headers Exchange

In rabbitmq, headers exchanges will use the message header attributes for routing.

 

Following is the pictorial representation of message flow in rabbitmq headers exchange.

 

RabbitMQ Headers Exchange Process Flow Diagram

Now we will see how to add exchanges in rabbitmq using web management plugin.

RabbitMQ Create Exchange

To create new exchanges, first open rabbtimq web management portal, enter a default credentials to login and then choose Exchanges tab.

 

RabbitMQ Server Web Management Login Screen

 

After navigate to Exchanges tab, you will see “Add a new exchange panel” just click on that panel to expand and that will contain a different properties to create a new exchange like as shown below.

 

Creating a new exchange in rabbitmq

RabbitMQ Exchange Properties

Following are the different type of properties which we need to fill to create a new exchange in rabbitmq.

 

PropertyDescription
Name The name will be an exchange name which you will set and it must be unique.
Type You can select required exchange type either topic or fanout, etc. based on your requirements.
Durability By using durability (Durable, Transient) properties, we can make the message to survive even after server restarts. If we select Durable, then the message will survive even after server restart. In case, if we select Tansient, then message will not service after server restart.
Auto Delete By using auto delete property, we can set whether an exchange can delete if we unbind assigned queue.
Internal If we set this property yes, then the exchange may not be used directly by publishers, but only when bound to other exchanges.
Alternate-exchange If there is an issue in publishing message to exchange, then by using this property, we can specify an alternate exchange to send a message to queue.

Once we enter all required details, then click Add exchange button to create a new exchange like as shown below.

 

 Click on Add exchange button to create exchange in rabbitmq

 

After creating the exchange, we can see our newly created exchange under exchanges tab like as shown below.

 

RabbitMQ Exchanges Lists

 

In a similar way, we can create various exchanges with different types based on our requirements.