RabbitMQ routing key wildcards: routing key vs binding key
Codemia Knowledge Hub ·
In a RabbitMQ topic exchange, wildcards go in the binding key, not the routing key. The producer sets a precise routing key such as asia.china.beijing, and each queue binds with a pattern such as asia.*.* or europe.#. The exchange delivers the message to every queue whose binding pattern matches the routing key.
Routing key vs binding key
A routing key is an attribute the producer adds to a message. It describes the route the message should take when it reaches an exchange. A binding key defines the binding between a queue and an exchange.
Topic exchange wildcards
Binding keys in a topic exchange support two special characters:
*(asterisk) matches exactly one word.#(hash) matches zero or more words.
A "word" is a string of characters delimited by dots (.). These characters are special only in binding keys. In a routing key they have no wildcard meaning; the routing key is matched as a list of words.
Example: three messages, three queues
Messages published to a topic exchange with these routing keys:
asia.china.beijingasia.india.delhieurope.uk.london
Queues bound with these binding keys:
- Queue A:
asia.*.* - Queue B:
*.china.* - Queue C:
europe.#
Delivery:
- Message 1 with routing key
asia.china.beijing:- Delivered to Queue A (matches
asia.*.*) - Delivered to Queue B (matches
*.china.*)
- Message 2 with routing key
asia.india.delhi:- Delivered to Queue A (matches
asia.*.*)
- Message 3 with routing key
europe.uk.london:- Delivered to Queue C (matches
europe.#)
Who uses wildcards
- Routing key: the producer's clear, precise identifier for the message. It does not use wildcards.
- Binding key: used extensively in topic exchanges so that queues subscribe to a pattern of messages. Consumers can filter on several criteria expressed in the pattern.
| Feature | Routing Key | Binding Key |
| Purpose | Directs the message to the appropriate queues based on content. | Defines patterns to filter messages desired by a queue. |
| Wildcard Use | Generally not used with wildcards. | Often uses wildcards to define broad or specific patterns. |
| Examples | log.info, user.data.update | *.info, user.#, log.* |
Misconfigured patterns
Getting the combination of routing and binding keys wrong leads to messages that are never delivered, or to queues flooded with messages they do not want. Check each binding pattern against the routing keys your producers actually send.
Related reading
- RabbitMQ 3.3.1 can not login with guest/guest
- RabbitMQ 3.5 and Message Priority
- RabbitMQ 3.6.1 / Erlang 18.3 TLS insufficient security failures
- RabbitMQ / ActiveMQ or Redis for over 250,000 msg/s
- RabbitMQ / AMQP single queue, multiple consumers for same message?
- RabbitMQ + C# + SSL
- RabbitMQ + Memory Limits
- RabbitMQ ** WARNING ** Mnesia is overloaded
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.