0
0
RabbitMQdevops~30 mins

Direct exchange in RabbitMQ - Mini Project: Build & Apply

Choose your learning style9 modes available
Direct Exchange in RabbitMQ
📖 Scenario: You are setting up a messaging system using RabbitMQ. You want to send messages to specific queues based on exact routing keys using a direct exchange.
🎯 Goal: Build a RabbitMQ setup with a direct exchange, bind queues with specific routing keys, and send messages that are routed correctly.
📋 What You'll Learn
Create a direct exchange named direct_logs
Create two queues named info_queue and error_queue
Bind info_queue to direct_logs with routing key info
Bind error_queue to direct_logs with routing key error
Publish messages with routing keys info and error to the exchange
Consume messages from both queues and print them
💡 Why This Matters
🌍 Real World
Direct exchanges are used in messaging systems where messages must be routed exactly to queues based on routing keys, such as logging systems or task dispatchers.
💼 Career
Understanding direct exchanges is essential for roles involving message brokers, microservices communication, and event-driven architectures.
Progress0 / 4 steps
1
Create the direct exchange and queues
Create a direct exchange called direct_logs. Create two queues called info_queue and error_queue.
RabbitMQ
Need a hint?

Use exchange_declare with exchange_type='direct' and queue_declare for queues.

2
Bind queues to the direct exchange with routing keys
Bind the queue info_queue to the exchange direct_logs with routing key info. Bind the queue error_queue to the exchange direct_logs with routing key error.
RabbitMQ
Need a hint?

Use queue_bind with the correct exchange, queue, and routing_key.

3
Publish messages with routing keys
Publish a message 'Info message' with routing key info to the exchange direct_logs. Publish a message 'Error message' with routing key error to the same exchange.
RabbitMQ
Need a hint?

Use basic_publish with the correct exchange, routing_key, and body.

4
Consume and print messages from both queues
Consume one message from info_queue and print it. Then consume one message from error_queue and print it.
RabbitMQ
Need a hint?

Use basic_get to get messages from queues and print the decoded body.