Product SiteDocumentation Site

1.3. Exchange Types

Every message is sent through an exchange, which determines how to distribute the message. In MRG Messaging there are three standard exchanges and a custom exchange type:
  • Fanout
  • Direct
  • Topic
  • Custom Exchange
Fanout Exchange
The fanout exchange will distribute messages to every queue. Any routing information provided by the producer is ignored.
Direct Exchange
In a direct exchange the broker will search for matches between the message's routing key and the queues' binding keys. If the broker finds an exact match, it will deliver the message to that queue.
Topic Exchange
A topic exchange uses multi-part keys to find matches between routing keys and binding keys. Topic exchanges can also use wildcard characters to find matches.
This example demonstrates the use of multi-part keys in a topic exchange
A message producer creates four messages concerning news and weather in the United States of America and Europe. The producer creates four different routing keys for the messages, each of which contains two parts. The two parts of the routing keys are separated with a . (period) character:
  1. usa.news
  2. usa.weather
  3. europe.news
  4. europe.weather
There are currently four queues bound to the topic exchange. The four queues collect information on:
  1. Everything related to the USA
  2. All news
  3. All weather
  4. Everything related to Europe
These are defined as a two-part binding key, with the # (pound) character as a wildcard:
  1. usa.#
  2. #.news
  3. #.weather
  4. europe.#
So, in this example, the message with the routing key of usa.weather will be delivered to two queues - usa.# and #.weather. Similarly, the message with the routing key of europe.news will be delivered to the queues with the binding keys europe.# and #.news
Example 1.1. Using multi-part keys with a topic exchange

Custom Exchange Types
Exchange types that do not fit the standard set of exchanges are referred to as custom exchanges. MRG Messaging provides a custom exchange that operates with the Extensible Markup Language XML.
The custom XML exchange sends messages written in XML. The messages contain bindings written in the XML query language XQuery. It is implemented as an optional module in MRG Messaging.