0
0
RabbitMQdevops~10 mins

Binding keys and routing keys in RabbitMQ - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Binding keys and routing keys
Producer sends message with Routing Key
Exchange receives message
Exchange compares Routing Key with Binding Keys
Match Binding Key
Route to Queue
Consumer receives message
Messages are sent with a routing key to an exchange, which routes them to queues whose binding keys match the routing key.
Execution Sample
RabbitMQ
Producer sends message with routing key 'info'
Exchange has bindings: 'info', 'error'
Exchange routes message to queues with matching binding keys
This example shows how a message with routing key 'info' is routed to queues bound with 'info'.
Process Table
StepRouting KeyBinding Key CheckedMatch?ActionResulting Queue
1infoinfoYesRoute messageQueue1
2infoerrorNoIgnore-
3infoinfo.*NoIgnore-
4infoinfo.#YesRoute messageQueue3
5infoerror.*NoIgnore-
6infoerror.#NoIgnore-
7info-No more bindingsStop routing-
💡 All binding keys checked; message routed to matching queues Queue1 and Queue3
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6Final
Routing Keyinfoinfoinfoinfoinfoinfoinfoinfo
Binding Key-infoerrorinfo.*info.#error.*error.#-
Match Result-YesNoNoYesNoNo-
Queues Routed[][Queue1][Queue1][Queue1][Queue1, Queue3][Queue1, Queue3][Queue1, Queue3][Queue1, Queue3]
Key Moments - 3 Insights
Why does the message route to Queue3 even though the binding key is 'info.#'?
Because 'info.#' matches routing keys starting with 'info' followed by zero or more words, so 'info' matches 'info.#' as shown in execution_table row 4.
Why is there no match with 'info.*' binding key?
'info.*' matches routing keys with exactly two words starting with 'info', but 'info' is a single word, so no match occurs (execution_table row 3).
What happens if no binding keys match the routing key?
The message is discarded or ignored by the exchange, as shown in execution_table row 7 where no more bindings match.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which binding key first matches the routing key 'info'?
A'info'
B'error'
C'info.*'
D'error.#'
💡 Hint
Check the 'Match?' column in execution_table row 1.
At which step does the routing key match a binding key with a wildcard?
AStep 2
BStep 3
CStep 4
DStep 6
💡 Hint
Look for binding keys with '#' or '*' wildcards in execution_table.
If the routing key was 'info.update', which binding key would match?
A'info'
B'info.*'
C'error.#'
D'error'
💡 Hint
Refer to how 'info.*' matches routing keys with two words starting with 'info'.
Concept Snapshot
Binding keys connect queues to exchanges.
Routing keys label messages sent to exchanges.
Exchange routes messages to queues where binding keys match routing keys.
'*' matches exactly one word; '#' matches zero or more words.
Messages with no matching binding keys are discarded.
Full Transcript
In RabbitMQ, messages are sent with routing keys to an exchange. The exchange checks each binding key attached to queues. If the routing key matches a binding key, the message is routed to that queue. Binding keys can include wildcards: '*' matches exactly one word, '#' matches zero or more words. For example, a routing key 'info' matches binding keys 'info' and 'info.#' but not 'info.*'. If no binding keys match, the message is discarded. This process ensures messages reach the correct queues based on their routing keys.