A Topic Exchange routes messages to queues based on matching between a message routing key and the pattern that was used to bind a queue to the exchange. It uses wildcards for flexible routing.
Click to reveal answer
beginner
What wildcard characters are used in Topic Exchange bindings?
The '*' (star) matches exactly one word, and the '#' (hash) matches zero or more words in the routing key.
Click to reveal answer
intermediate
How does the routing key 'stock.usd.nyse' match the binding key 'stock.*.*'?
The routing key 'stock.usd.nyse' matches 'stock.*.*' because '*' matches exactly one word. Here, 'usd' and 'nyse' each match one '*'.
Click to reveal answer
intermediate
Explain the difference between '*' and '#' in Topic Exchange pattern matching.
'*' matches exactly one word in the routing key, while '#' matches zero or more words, allowing more flexible matching.
Click to reveal answer
beginner
What happens if a message's routing key does not match any binding pattern in a Topic Exchange?
The message is discarded or returned to the sender if no queue binding matches the routing key pattern in the Topic Exchange.
Click to reveal answer
Which wildcard in a Topic Exchange matches zero or more words?
A#
B*
C?
D%
✗ Incorrect
The '#' wildcard matches zero or more words in the routing key pattern.
What does the routing key 'log.error.system' match if the binding key is 'log.*.*'?
AMatches only if '#' is used
BDoes not match
CMatches only if '*' is replaced by '#'
DMatches
✗ Incorrect
Each '*' matches exactly one word, so 'error' and 'system' match the two '*' in 'log.*.*'.
If a queue is bound with 'sensor.#', which routing key will NOT match?
Asensor.temperature
Bsensor.temperature.outdoor
Cdevice.sensor.temperature
Dsensor
✗ Incorrect
'device.sensor.temperature' does not start with 'sensor', so it does not match the binding key 'sensor.#'.
What type of exchange uses pattern matching with wildcards '*' and '#'?
ADirect Exchange
BTopic Exchange
CFanout Exchange
DHeaders Exchange
✗ Incorrect
Topic Exchange uses routing keys with '*' and '#' wildcards for pattern matching.
Which binding key would match routing keys with exactly three words starting with 'app'?
Aapp.*.*
Bapp.#
C*.app.*
D#.app
✗ Incorrect
'app.*.*' matches routing keys with three words where the first word is 'app'.
Describe how the '*' and '#' wildcards work in RabbitMQ Topic Exchange pattern matching.
Think about how many words each wildcard can match in the routing key.
You got /3 concepts.
Explain what happens when a message is sent to a Topic Exchange with a routing key that does not match any queue binding.
Consider how routing keys and binding keys interact in message delivery.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a topic exchange in RabbitMQ?
easy
A. To broadcast messages to all queues regardless of routing keys
B. To store messages until consumers are ready
C. To route messages based on pattern matching of routing keys
D. To encrypt messages before sending
Solution
Step 1: Understand the role of exchanges in RabbitMQ
Exchanges route messages to queues based on rules. Topic exchanges use patterns in routing keys.
Step 2: Identify the unique feature of topic exchanges
Topic exchanges route messages by matching routing keys with patterns containing * and # wildcards.
Final Answer:
To route messages based on pattern matching of routing keys -> Option C
Quick Check:
Topic exchange = pattern matching routing [OK]
Hint: Topic exchange uses wildcards to match routing keys [OK]
Common Mistakes:
Confusing topic exchange with fanout exchange
Thinking topic exchange stores messages
Assuming topic exchange encrypts messages
2. Which of the following is the correct syntax to bind a queue named logs to a topic exchange named topic_logs with routing key pattern kern.* using RabbitMQ CLI?
easy
A. rabbitmqadmin declare binding source=topic_logs destination=logs routing_key=kern.*
B. rabbitmqctl bind queue=logs exchange=topic_logs routing_key=kern.*
C. rabbitmqadmin bind queue=logs exchange=topic_logs routing_key=kern.*
D. rabbitmqctl declare binding source=topic_logs destination=logs routing_key=kern.*
Solution
Step 1: Identify the correct RabbitMQ CLI tool for binding
Binding queues to exchanges is done with rabbitmqadmin declare binding, not rabbitmqctl.
Step 2: Check the correct parameters for binding
The correct parameters are source for exchange, destination for queue, and routing_key for pattern.
Final Answer:
rabbitmqadmin declare binding source=topic_logs destination=logs routing_key=kern.* -> Option A
Quick Check:
Use rabbitmqadmin declare binding with source, destination, routing_key [OK]
Hint: Use rabbitmqadmin declare binding with source and destination [OK]
Common Mistakes:
Using rabbitmqctl instead of rabbitmqadmin for binding
Swapping source and destination parameters
Omitting routing_key parameter
3. Given a topic exchange with a queue bound using the routing key pattern *.orange.*, which routing keys will deliver messages to this queue?
medium
A. quick.orange.rabbit, orange
B. orange.rabbit, quick.orange
C. quick.orange, orange.lazy.rabbit
D. quick.orange.rabbit, lazy.orange.elephant
Solution
Step 1: Understand the pattern *.orange.*
The pattern means exactly three words separated by dots, with 'orange' as the middle word. The * matches exactly one word.
Step 2: Check each routing key against the pattern
quick.orange.rabbit, lazy.orange.elephant keys: 'quick.orange.rabbit' and 'lazy.orange.elephant' both have three words with 'orange' in the middle, so they match.
Final Answer:
quick.orange.rabbit, lazy.orange.elephant -> Option D
Quick Check:
Pattern *.orange.* matches three-word keys with orange in middle [OK]
Hint: Count words; * matches one word, # matches zero or more [OK]
Common Mistakes:
Assuming * matches zero or multiple words
Ignoring word count in routing key
Confusing * with # wildcard
4. You have a queue bound to a topic exchange with the routing key pattern stock.#. Messages with routing key stock.us.nyse are not delivered to the queue. What is the most likely cause?
medium
A. The exchange type is not set to topic
B. The routing key pattern stock.# does not match stock.us.nyse
C. The queue is not bound correctly to the exchange
D. The message was published with an empty routing key
Solution
Step 1: Verify the exchange type
The pattern stock.# matches routing keys starting with 'stock' followed by zero or more words. If messages are not delivered, the exchange might not be a topic exchange.
Step 2: Check other possible causes
Binding and routing key pattern are correct. If the exchange is not topic type, pattern matching won't work.
Final Answer:
The exchange type is not set to topic -> Option A
Quick Check:
Topic exchange required for pattern matching [OK]
Hint: Ensure exchange type is topic for pattern matching [OK]
Common Mistakes:
Assuming binding is always correct without verification
Thinking # wildcard doesn't match multiple words
Ignoring exchange type setting
5. You want to receive all messages related to any fruit except those about apples or bananas using a topic exchange. Which binding key pattern should you use?
hard
A. *.fruit.*
B. #.fruit.# and bind separate queues for apple and banana to discard
C. #.fruit.# but exclude apple and banana keys manually
D. #.fruit.#
Solution
Step 1: Understand topic exchange limitations
Topic exchanges route messages by matching patterns but cannot exclude specific keys directly in binding patterns.
Step 2: Plan a solution using multiple queues
Bind one queue with #.fruit.# to get all fruit messages. Bind separate queues for apple and banana keys to handle or discard them separately.
Step 3: Implement exclusion by filtering in consumers or separate queues
Since exclusion is not supported in binding keys, use separate queues or consumer logic to exclude apples and bananas.
Final Answer:
#.fruit.# and bind separate queues for apple and banana to discard -> Option B
Quick Check:
Exclusion requires separate queues or consumer filtering [OK]
Hint: Topic exchange can't exclude keys; use separate queues [OK]
Common Mistakes:
Trying to exclude keys using binding patterns
Assuming * or # can exclude specific words
Not using multiple queues or consumer filtering
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.