from:http://lostechies.com/derekgreer/2012/03/28/rabbitmq-for-windows-exchange-types/
RabbitMQ for Windows:exchange TypesPosted by Derek Greer on March
This was the fourth installment to the SERIES:RABBITMQ for Windows. In the last installment, we reviewed our Hello World example and introduced the concept of exchanges. In this installment, we'll discuss the four basic types of RabbitMQ exchanges.
Exchange Types
Exchanges control the routing of messages to queues. Each exchange type defines a specific routing algorithm which the server uses to determine which bound queues a published Message should is routed to.
RabbitMQ provides four types of Exchanges:direct, Fanout, Topic, and Headers.
Direct Exchanges
The Direct Exchange type routes messages with a routing key equal to the routing key declared by the binding queue. [Puncha: The author wants to express: This routingkey is specified when binding Exchange and queue. ]. The following illustrates how the direct exchange type works:
The Direct exchange type is useful if you would like Todistinguish messages published to the same exchange using a Simpl E string identifier. This is the type of exchange, which was used in we Hello world example. As discussed in Part 3 of our series, every queue are automatically bound to a default exchange using a routing key equal T o the queue name. This default exchange is declared as a Direct exchange. In our example, the queue named "Hello-world-queue" is bound to the default exchange with a routing key of "hello-world-q Ueue ", so publishing a message to the default exchange (identified with an empty string) routed the message to the queue n Amed "Hello-world-queue".
Fanout Exchanges
The Fanout Exchange type routes messages to all bound queues indiscriminately. If A routing key is provided, it'll simply be ignored. The following illustrates how the Fanout exchange type works:
The Fanout exchange type is useful for facilitating the publish-subscribe pattern. When using the Fanout exchange type, different queues can is declared to handle messages in different ways. For instance, a message indicating a customer order have been placed might be received by one queue whose consumers fulfill The order, another whose consumers update a read-only history of orders, and yet another whose consumers record the order for reporting purposes.
Topic Exchanges
The Topic Exchange type routes messages to queues whose routing key matches all, or a portion of a routing key. With topic exchanges, messages is published with routing the keys containing a series of words separated by a dot (e.g. "word 1.word2.word3 "). Queues binding to a topic exchange supply a matching pattern for the server to use when routing the message. Patterns contain an asterisk ("*") to match a word in a specific position of the routing key, or a hash ("#") to match zero or more words. For example, a message published with a routing key of "Honda.civic.navy" would match queues bound with "Honda.civic.navy" , "*.civic.*", "honda.#", or "#", but would not match "Honda.accord.navy", "Honda.accord.silver", "*.accord.*", or "ford.# ”. The following illustrates how the Fanout exchange type works:
The Topic exchange type is useful for directing messages based on multiple categories (e.g. product type and shipping pref erence), or for routing messages originating from multiple sources (e.g. logs containing an application name and severity Level).
Headers Exchanges
The Headers Exchange type routes messages based upon amatching of message Headers to the expected Headers specified by the Binding queue. The headers exchange type is similar to the topic Exchange type in and the than one criteria can be specified as a Filte R, but the headers exchange differs in that it criteria is expressed in the message headers as opposed to the routing key , may occur on any order, and could be specified as matching any or all of the specified headers. The following illustrates how the headers Exchange type works: [Puncha: Note that there is a x-match, the difference between any and all]
The Headers exchange type is useful for directing messages which could contain a subset of known criteria where the order is Not established and provides a more convenient to ofmatching based upon the use of complex types as the matching Criteri A (i.e. a serialized object).
Conclusion
That's wraps up we introduction to each of the exchange types. Next time, we ' ll walk through an example which demonstrates declaring a direct exchange explicitly and take a look at the The push API.
http://blog.csdn.net/puncha/article/details/8449383
RABBITMQ Learning: (v) Exchange Type (repost + my comments)