0
0
RabbitMQdevops~20 mins

Direct exchange in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Direct Exchange Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
How does a direct exchange route messages in RabbitMQ?

In RabbitMQ, a direct exchange routes messages based on which of the following?

AThe message header contains a matching key-value pair
BThe exchange randomly selects a queue to send the message
CThe message is broadcast to all queues regardless of keys
DThe routing key exactly matches the binding key of the queue
Attempts:
2 left
💡 Hint

Think about how direct exchanges use routing keys to deliver messages.

💻 Command Output
intermediate
1:30remaining
What is the output of binding a queue with a routing key?

Given the RabbitMQ command below, what is the expected result?

rabbitmqadmin declare binding source=direct_logs destination=my_queue routing_key=error
AThe queue 'my_queue' will receive all messages from 'direct_logs' exchange regardless of routing key
BThe queue 'my_queue' will receive messages sent to 'direct_logs' exchange with routing key 'error'
CThe command will fail because 'routing_key' is not valid in binding declaration
DThe queue 'my_queue' will receive messages only if the exchange type is 'fanout'
Attempts:
2 left
💡 Hint

Consider what binding with a routing key does in a direct exchange.

🔀 Workflow
advanced
2:00remaining
Order the steps to set up a direct exchange with a queue and binding

Arrange the following steps in the correct order to set up a direct exchange named 'logs', a queue named 'error_logs', and bind them with routing key 'error'.

A1,3,2,4
B2,1,3,4
C1,2,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint

Think about what must exist before binding and publishing.

Troubleshoot
advanced
1:30remaining
Why does a queue not receive messages from a direct exchange?

You have a direct exchange 'logs' and a queue 'info_logs' bound with routing key 'info'. You publish a message with routing key 'warning' but 'info_logs' does not receive it. Why?

ABecause the routing key 'warning' does not match the binding key 'info'
BBecause the queue 'info_logs' is not declared
CBecause the message was published to the wrong exchange type
DBecause direct exchanges broadcast messages to all queues regardless of routing key
Attempts:
2 left
💡 Hint

Recall how direct exchanges route messages based on routing keys.

Best Practice
expert
2:00remaining
Which practice ensures reliable message delivery with direct exchanges?

When using a direct exchange in RabbitMQ, which practice best ensures that messages are not lost if the consumer is temporarily offline?

ADeclare the queue as durable and publish messages as persistent
BUse a non-durable queue and transient messages for faster delivery
CBind multiple queues with different routing keys to the exchange
DPublish messages without specifying a routing key to reach all queues
Attempts:
2 left
💡 Hint

Think about how RabbitMQ handles message durability and persistence.