About Me
Eric Rodriguez
Founder @ Data.be
Founder @ Pictawall.com
CTO @ Auctelia.com
!
• Web entrepreneur
• Multi-Language: PHP, Java/Groovy/Grails, .Net, …
!
be.linkedin.com/in/erodriguez
!
github.com/wavyx
!
@wavyx
Slide 3
Slide 3 text
Which Rabbit ?!
Slide 4
Slide 4 text
RabbitMQ
• Message Broker
• Open Source
• AMPQ implementation
• Written in Erlang
• Lots of AMQP client libraries
• Wide community and commercial support
Use Cases
• Send notifications to users
• Process heavy work/tasks with multiple workers
Upload picture, make thumbnails, clear CDN caches…
• Distribute logs/messages to multiple endpoints
• Interoperability between different platforms
• Remote Procedure Call
Slide 7
Slide 7 text
AMQP
Advanced Message Queuing Protocol
• Open Standard Protocol coming from finance
• Interoperable Messaging Middleware
• Queuing
• Routing (point-to-point and publish-and-subscribe)
• Reliability
• Security
Cloud Alternatives
• IronMQ
http://www.iron.io/mq
• Amazon SQS
http://aws.amazon.com/sqs/
• StormMQ
http://stormmq.com/
• Rackspace Queues
http://www.rackspace.com/cloud/queues/
• Windows Azure Service Bus
http://www.windowsazure.com/en-us/services/messaging/
Slide 15
Slide 15 text
PHP Implementation
• php-amqplib - pure php client
https://github.com/videlalvaro/php-amqplib
• PECL AMQP library - built on RabbitMQ C client
http://pecl.php.net/package/amqp
• amqphp - pure php client
https://github.com/BraveSirRobin/amqphp
• Thumper - library of messaging patterns
https://github.com/videlalvaro/Thumper
Slide 16
Slide 16 text
Hello MQ World - send
Slide 17
Slide 17 text
Hello MQ World - receive
Slide 18
Slide 18 text
Hello MQ World
queue_declare
Slide 19
Slide 19 text
Hello MQ World
basic_publish & basic_consume
Slide 20
Slide 20 text
Work Queues / Task Queues
• Avoid doing a resource-intensive task immediately
• Schedule the task to be done later
• Encapsulate a task as a message and send it to a
queue
• A worker process running in the background will
execute the job
• Multiple workers will share tasks
Slide 21
Slide 21 text
Work Queues - new_task
Slide 22
Slide 22 text
Work Queues - worker
Slide 23
Slide 23 text
Publish/Subscribe
• Task queues: task is delivered to exactly one worker
• Pub/Sub: deliver a message to multiple consumers
• Published messages are going to be broadcast to all
the receivers
• Fanout exchanges
Slide 24
Slide 24 text
Pub/Sub - emit_log
Slide 25
Slide 25 text
Pub/Sub - receive_logs
Slide 26
Slide 26 text
Routing
• Fanout => Direct exchange
• Subscribe only to a subset of the messages
• Filter messages based on their routing key
Slide 27
Slide 27 text
Routing - emit_log_direct
Slide 28
Slide 28 text
Routing - receive_logs_direct
Slide 29
Slide 29 text
Topics
• Direct exchanges cannot do routing based on multiple criteria
• Example: how to combine “severity” and “resource”
• Topic exchange: messages are sent with a routing key
composed by a list of words, delimited by dots
• * (star) can substitute for exactly one word
• # (hash) can substitute for zero or more words
Slide 30
Slide 30 text
Topics - emit_log_topic
Slide 31
Slide 31 text
Topics - receive_logs_topic
Slide 32
Slide 32 text
RPC
• Work Queues = distribute time-consuming tasks
among multiple workers
• Remote Procedure Call or RPC = run a function on a
remote computer and wait for the result