Menu Search

An Exchange is a named entity within the Virtualhost which receives messages from producers and routes them to matching Queues within the Virtualhost.

When using AMQP 0-8, 0-9, 0-9-1, or 0-10, the exchange is the only way ingressing a message into the virtualhost. When using AMQP 1.0, the application may route messages using an exchange (to take advantage of exchange's routing behaviours), or it may route direcly to a queue (if point to point messaging is required).

The server provides a set of exchange types with each exchange type implementing a different routing algorithm. For details of how these exchanges types work see Section 4.6.2, “Exchange Types” below.

The server predeclares a number of exchange instances with names starting with "amq.". These are defined in Section 4.6.1, “Predeclared Exchanges”.

Applications can make use of the pre-declared exchanges, or they may declare their own. The number of exchanges within a Virtualhost is limited only by resource constraints.

The behaviour when an Exchange is unable to route a message to any queue is defined in Section 4.6.4, “Unrouteable Messages”

The following Exchange types are supported.

These exchange types are described in the following sub-sections.

This exchange type is used to support the classic publish/subscribe paradigm.

The topic exchange is capable of routing messages to queues based on wildcard matches between the routing key and the binding key pattern defined by the queue binding. Routing keys are formed from one or more words, with each word delimited by a full-stop (.). The pattern matching characters are the * and # symbols. The * symbol matches a single word and the # symbol matches zero or more words.

Additional filter rules may be specified using a binding argument specifying a JMS message selector.

The following three figures help explain how the topic exchange functions.


The figure above illustrates publishing messages with routing key "weather". The exchange routes each message to every bound queue whose binding key matches the routing key.

In the case illustrated, this means that each subscriber's queue receives every yellow message.


The figure above illustrates publishing messages with hierarchical routing keys. As before, the exchange routes each message to every bound queue whose binding key matches the routing key but as the binding keys contain wildcards, the wildcard rules described above apply.

In the case illustrated, sub1 has received the red and green message as "news.uk" and "news.de" match binding key "news.#". The red message has also gone to sub2 and sub3 as it's routing key is matched exactly by "news.uk" and by "*.uk".

The routing key of the yellow message matches no binding keys, so the message is unroutable. It is handled as described in Section 4.6.4, “Unrouteable Messages”.


The figure above illustrates messages with properties published with routing key "shipping".

As before, the exchange routes each message to every bound queue whose binding key matches the routing key but as a JMS selector argument has been specified, the expression is evaluated against each matching message. Only messages whose message header values or properties match the expression are routed to the queue.

In the case illustrated, sub1 has received the yellow and blue message as their property "area" cause expression "area in ('Forties', 'Cromarty')" to evaluate true. Similarly, the yellow message has also gone to gale_alert as its property "speed" causes expression "speed > 7 and speed < 10" to evaluate true.

The properties of purple message cause no expressions to evaluate true, so the message is unroutable. It is handled as described in Section 4.6.4, “Unrouteable Messages”.



[4] This is a Qpid specific extension.