Chinese Yellow Pages | Classifieds | Knowledge | Tax | IME

RabiitMQ implement the  AMQP protocol. written in Erlang.

it is a quite useful message broker or message middleware.

It works like this:

sender or receiver can create different type of Exchanges.

Sender of course will send message to exchange.

The receiver will create a queue, and binding to the exchange.

The Exchange will route the msg to the receiver based on the exchange type and routing key etc.


Well the key is Exchange type!

There are several types of exchange


(1) default exchange

routing key is the same as queue  name.

(2) direct exchange.

a receiver r1 create a queue, and bind to the exchange with a key ( e.g: a1),  ( we may call it binding key,  in this case routing key is the same as binding key).

a sender s1 will send a msg with a routing key (e.g: a1) inside the msg

the exchange will routing the msg to r1 based on the routing key.

(3) Topic exchange.

not really much different from direct change, the exchange will route the msg based on a pattern match using the routing key.

and the routing key must be a list of words delimited by a period.


the receiver’s binding key become a pattern, like: education.*.usa or education.#

thus the exchange will do a pattern match based routing for the msg.


q1 binded as education.*.usa  ( * will do a single word match)

q2 binded as education.#    ( # means zero or more words match)

s1 send a msg with a routing key:, both q1, and q2 will receeve a msg


(4) FanOut Exchange

in this case msg will be routed to any queue bound to the exchange regardless the binding keys.


(5)  Header exchange

will use the any or all header/value   depending on the x-match header ( any or all )






Leave a Reply

Your email address will not be published. Required fields are marked *