RabbitMQ
Wildcard Usage
Routing Key
Binding Key
Message Queuing

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:

  1. asia.china.beijing
  2. asia.india.delhi
  3. europe.uk.london

Queues bound with these binding keys:

  • Queue A: asia.*.*
  • Queue B: *.china.*
  • Queue C: europe.#

Delivery:

  1. Message 1 with routing key asia.china.beijing:
    • Delivered to Queue A (matches asia.*.*)
    • Delivered to Queue B (matches *.china.*)
  2. Message 2 with routing key asia.india.delhi:
    • Delivered to Queue A (matches asia.*.*)
  3. 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.
FeatureRouting KeyBinding Key
PurposeDirects the message to the appropriate queues based on content.Defines patterns to filter messages desired by a queue.
Wildcard UseGenerally not used with wildcards.Often uses wildcards to define broad or specific patterns.
Exampleslog.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.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design