Thursday, January 27, 2011

Hello RabbitMQ

Conceptually, RabbitMQ is a message post office.

Casting
Broker is the physical post office.
Exchange is a named message box.
Queue is a queue.
Binding uses Routing Key to bind a Queue to an Exchange.
Producer delivers message to Exchange with a Routing Key.
Consumer consumes message from Queue.

Scenario
Broker: localhost
Exchange: StockMessageBox
Queue 1: 9OnQueue
Queue 2: 9SingQueue
Queue 3: 9BQueue
Binding 1: StockMessageBox => Price.700(Routing Key) => 9OnQueue
Binding 2: StockMessageBox => Price.716 => 9SingQueue
Binding 3: StockMessageBox => Price.# => 9BQueue
Producer: HKEX, which delivers stock price to StockMessageBox
Consumer: 9On, 9Sing, 9B, who consumes stock price from their queues

--
Now Producer HKEX publishes messages into StockMessageBox

JSON published: {Routing Key: Price.700, Close: 5.3}
Matched queues: 9OnQueue, 9BQueue

JSON published:{Routing Key: Price.716, Close: 3.2}
Matched queues: 9SingQueue, 9BQueue

JSON published:{Routing Key: Price.992, Close: 22.5}
Matched queues: 9BQueue

JSON published:{Routing Key: News.700, Info: "Profits increase 20%!"}
Matched queues: None
--

StockMessageBox(the Exchange) forward messages to queues by matching the Routing Key in the message and the Binding.13:19 27/01/2011

No comments:

Post a Comment