RabbitMQ is used in several example applications and real case studies. Three example codes demonstrate: 1) the RabbitMQ tutorial using request/reply queues, 2) RPC using correlated messages, and 3) Celery's distributed task queue using polling. Case studies show RabbitMQ for: 1) message passing between Zenoss daemons, 2) Nova controller RPC, 3) Instagram's task queue with Celery, 4) MercadoLibre's service bus architecture, and 5) Indeed.com's distributed crawling. RabbitMQ provides reliability, scalability, and asynchronous messaging between distributed applications and microservices.
4. Notations in RabbitMQ Model
s4
application
thread
virtual
host
TCP
connection
exchange
channel
binding
message
queue
consuming
5. RabbitMQ Model
• Virtual Host
• Exchange
– direct
– fan-out
– topic
• Binding
– topic
– cascading
– message select
• queue
– flags: private, durable
• Connection
– channel: every thread work
with one channel
• Message
– content header
• Properties: Reply-To, Cor-Id,
Message-Id, Key
• queue server may add
properties , wont remove/
modify
– content body (wont modify)
• binary/ file/ stream
• Application
– client/ server
6. Other Items in AMQP 0.8,
not included in Model
– AMQP transaction – deliver ACK to sender after
message received
– AMQP distributed transaction – deliver ACK to a
3rd party software after message received
– Access – a realm based access control model
we think these are irrelevant to ADDM
transaction detection
10. Classical Scenario
in Example Code
– one request queue per service; one reply queue per client
– properties used on message
• correlate-id
• message-id
• reply-to
– steps
1.
2.
3.
4.
client thread send REQUEST and wait on reply queue
server thread receive REQUEST, process it and send REPLY to reply queue
client thread get reply from reply queue
if asynchronous mode, client may polls processing status by another status
update REQUEST message, and server reply another status update REPLY
message
15. Celery: one client application with two worker
w1
service
C1
w1
2+2
1+1
cor-id: (2)
cor-id: (1)
worker thread pool
1. client make two calls via the same connection
w1
C1
2
cor-id: (1)
w2
4
cor-id: (2)
2. worker send REPLY via its own connection
3. client receive REPLYs via the same connection
16. 5 Real Cases Study
• Applications use RabbitMQ
1. Zenoss4‘s message bus between daemons (non
transaction app)
2. Nova controller’s RPC call between hosts (transaction app)
• Enterprise use RabbitMQ
3. Instagram : Celery + RabbitMQ
4. MercadoLibre: RabbitMQ
5. Indeed.com
MailboxApp
17. Case 1: Zenoss 4
• A message bus to pass event and heartbeat between daemons
– RabbitMQ as message queue server
– Protobufs to serialization
• Non-transaction application
zenhub
zenoss
event server
heart
beat
event
zenhubworker
zeventd
raw
event
RabbitMQ
21. Case 2: Nova Controller
• A message queue server for RPC call between hosts
• Each RPC call has its own unique message-id generated by UUID library
22. Case 3: Instagram
• Web server uses nginx
• Messaging system use
RabbitMQ
– Scalability: self-made message
broker, dispatch message in RR
– Reliability: RabbitMQ cluster
• Worker system use Celery
– Celery is distributed task queue
– worker concurrency model
• slow task: pre-fork pool
• fast task: gevent
• Overall throughput
– 25k application threads
publishing task
– 4K tasks per second
– Also monitor queue length
http://lanyrd.com/2013/pycon/scdyrp/
23. Nginx Server with Celery
nginx
w1
client1
1
cor-id: (c1’s request)
w2
client
client
client
10k
10k
10k
2
cor-id: (c2’s request)
queue server
Nginx
• single thread
• event driven
• asynchronous (non-blocking)
• Task complete and
return REPLY messages
24. Case 4: MercadoLibre
• MercadoLibre is 8th largest ecommerce company in
Latin American
• original architecture of their ecommerce system:
requests
requests
requests
Redis
nodeJS
nginx
proxy
to route
requests
20 million request per
minutes, 4GB per seconds
Grails
Groovy
7000+ vm insance
(by openstack)
MongoDb
25. Case 4: MercadoLibre
• Changes from LB + web
app to enterprise
service bus architecture
• Benefit
–
–
–
–
error handling
routing
scalability
event driven for higher
performance
web
server
app1
req
app2
item
feed
req
enterprise
service bus
app3
persist
29. Reference
•
•
•
•
•
•
•
RabbitMQ specification 0.8
RabbitMQ Tutorial, example 1/6 and its packet dump
Celery: Distributed Task Queue and its packet dump
Messaging at Scale at Instagram
How is nginx different from apache
Zenoss source code
nova controller source code