Publish Subscribe with RabbitMQ Direct Exchange
Publish-subscribe pattern allows multiple consumers to consume the same message.
Publish Subscribe with RabbitMQ Direct Exchange
Publish-subscribe pattern allows multiple consumers to consume the same message.

Lets evaluate the Routing Key and the Direct exchange of RabbitMQ for the Publish-Subscribe pattern.
RabbitMQ
RabbitMQ is an open source message broker software.

Originally implemented the AMQP and supports other protocols such as Streaming Text Oriented Messaging Protocol (STOMP), Message Queuing Telemetry Transport (MQTT). Message broker queue oriented RabbitMQ consumer receives the message.
Installation of RabbitMQ
The documentation explains several approaches to install the RabbitMQ.
Below examples experimented with the Linux/Unix, Debian and Ubuntu distributions installation of the RabbitMQ.
Management Plugin
The RabbitMQ documentation provides an overview of the management plugin and explains steps to enable the plugin.
Once enable the plugin, visit http://localhost:15672/ from the web browser to access the Management UI.
Publish-Subscribe Messages

- Create Queues


- Create an Exchange
Navigate to the Exchanges tab of the RabbitMQ Management UI.

Current Bindings of the Exchange

Current Bindings of the Queues


- Create Bindings
Navigate to the Exchanges tab of the RabbitMQ Management UI and click on the Exchange name and expand the Bindings section.
Binding exchange and first queue along with routing_key_1

Binding exchange and second queue along with routing_key_1 and routing_key_2


Exchange should be updated with the bindings

Also Queues should be updated with the bindings


- Publish message
Let’s navigate to the exchange and publish a message with routing key 1.

Now publish a message with routing key 2.

Messages sections of both Queues should be updated with new messages based on the routing key.
According to the routing key configurations, first queue should receive only the message with routing_key_1 and the second queue should receive both routing_key_1 and routing_key_2 messages.

First queue should indicate a single message and second should indicate two messages.


- Consume Message
Click on the first queue and expand the Get Messages section. Update the Ack Mode value, Messages count and click on the Get Message(s).


Similarly click on the second queue and expand the Get Messages section. Update the Ack Mode value, Messages count and click on the Get Message(s).


In this scenario, it considers the routing key and routes messages based on the routing key values of the bindings and routing key values of the messages. This used a direct exchange and queues bound with queues using routing key of the binding.
메타데이터
- post_id
- b41b1c236bbe
- slug
- publish-subscribe-with-rabbitmq-direct-exchange-b41b1c236bbe
- url
- https://medium.com/@pawara/publish-subscribe-with-rabbitmq-direct-exchange-b41b1c236bbe
- canonical_url
- https://medium.com/@pawara/publish-subscribe-with-rabbitmq-direct-exchange-b41b1c236bbe
- author_url
- https://medium.com/@pawara
- status
- ok
- fetched_at
- 2026-06-23 17:05:31