SlideShare a Scribd company logo
Practical Message
Queueing Using
RabbitMQ
James Titcumb
PHPem
3rd July 2014
James Titcumb
www.jamestitcumb.com
www.protected.co.uk
www.phphants.co.uk
@asgrim
Who is this guy?
Who are you?
https://www.flickr.com/photos/akrabat/10168019755/
What is message
queueing?
Separation of Concerns
Scaling with Rabbit
RabbitMQApplication
Background processing
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
Background processing
● Fast logging solution
Some real world uses...
● Fast logging solution
● Background Processing
Some real world uses...
● Fast logging solution
● Background Processing
○ Sending emails
Some real world uses...
● Fast logging solution
● Background Processing
○ Sending emails
○ Sending SMS
Some real world uses...
● Fast logging solution
● Background Processing
○ Sending emails
○ Sending SMS
○ Analytics, reporting
Some real world uses...
(on precise64, other OSs may vary)
Installing RabbitMQ
● add apt repo
○ deb http://www.rabbitmq.com/debian/ testing main
● add signing key
○ http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
● apt-get update
● apt-get install rabbitmq-server
● rabbitmq-plugins enable rabbitmq_management
● sudo service rabbitmq-server restart
Using Apt
http://localhost:15672/
Basic Message Queuing
Objective: Basic Queuing
Producer Consumer
test_queue
1 2 3 4 5
composer.json
{
"require": {
"videlalvaro/php-amqplib": "2.*"
}
}
then composer install
Please wait, connecting...
use PhpAmqpLibConnectionAMQPConnection;
$connection = new AMQPConnection(
'localhost',
5672,
'guest',
'guest',
'/'
);
$channel = $connection->channel();
basic/producer.php
use PhpAmqpLibMessageAMQPMessage;
$channel->queue_declare(
'test_queue',
false,
true,
false, false);
$message = new AMQPMessage('my test message');
$channel->basic_publish($message, '', 'test_queue');
basic/consumer.php
$channel->basic_consume(
'test_queue', // Queue to consume
'', // Consumer identifier
false,
true, // No-ack means messages are "auto acknowledged"
false, // Exclusive - no other consumers can use the queue
false,
function(AMQPMessage $message) {
echo $message->body . "n";
}
);
while (count($channel->callbacks)) {
$channel->wait();
}
What to expect...
Exchanges: Fanout
Objective: Fanout Exchange
test_exchange
amq.KfgPZ3PE
amq.cK5Cp3FC
Consumer
Consumer
Producer
1
1
2
2
3
3
4
4
5
5
fanout/producer.php
use PhpAmqpLibMessageAMQPMessage;
$channel->exchange_declare(
'test_exchange',
'fanout',
false, false, false);
$message = new AMQPMessage('my test message #' . $id);
$channel->basic_publish($message, 'test_exchange');
fanout/consumer.php
$q = $channel->queue_declare(
'', // Lets RabbitMQ pick a name for queue
false, false, false,
true // Delete this queue
);
$queue_name = $q[0];
$channel->exchange_declare(
'test_exchange', 'fanout', false, false, false);
$channel->queue_bind($queue_name, 'test_exchange');
What to expect...
A word on Temporary Queues
● Only the “current” flow
● Specific use cases
test_exchangeProducer
Messages
go nowhere
Exchanges: Direct
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
3
Message Routing Keys
1 = orange
2 = banana
3 = apple
2 3
BK = orange, banana,
apple
Consumer1 2 3
direct/producer.php
$channel->exchange_declare(
'test_direct', 'fanout', false, false, false);
$messageContent = 'my test message, key=' . $routingKey;
$message = new AMQPMessage($messageContent);
$channel->basic_publish($message, 'test_direct', $routingKey);
direct/consumer.php
$q = $channel->queue_declare('', false, false, false, true);
$queue_name = $q[0];
$channel->exchange_declare(
'test_direct', 'direct', false, false, false);
// Bind for each routing key we want (BINDING KEY)
$channel->queue_bind($queue_name, 'test_direct', 'apple');
$channel->queue_bind($queue_name, 'test_direct', 'orange');
$channel->queue_bind($queue_name, 'test_direct', 'banana');
What to expect...
Exchanges: Topic
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
1 2
Message Routing Keys
1 = red.vegetable
2 = green.vegetable
3 = green.fruit
4 = red.meat
5 = green.grass.long
1 2 3 4 5
BK = green.#
Consumer2 3 5
BK = *.grass.* / *.*.long
Consumer5
Real World Example
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Fetch message
Logging Sequence
ApplicationBrowser Log Server
HTTP request
JSON via AMQP
Error!
HTTP response
RabbitMQ
Flexibility!
● Temporary Queues
○ e.g. inspect “debug” messages
Flexibility!
● Temporary Queues
● Queues to log to DB
Flexibility!
● Temporary Queues
● Queues to log to DB
● Queues to email “alert/emergency”
Flexibility!
● Temporary Queues
● Queues to log to DB
● Queues to email “alert/emergency”
● Get creative with routing keys
○ RK = app.api.error … BK = #.api.error
○ RK = app.form.debug … BK = #.debug
Problem: SPOF
Solution 1: Clustering
Clustering
RabbitMQ
Node 1
RabbitMQ
Node 3
RabbitMQ
Node 2
RabbitMQ
Node 4
RabbitMQ
Node 5
RabbitMQ
Node 6
Load Balance / Floating IP / Low TTL DNS etc.
Clustering
● Everything replicated, except queues
Clustering
● Everything replicated, except queues
● Types:
○ RAM
○ Disk
Clustering
● Everything replicated, except queues
● Types:
○ RAM
○ Disk
● Configuration:
○ CLI (rabbitmqctl)
○ Configuration files
Creating a cluster
node1$ rabbitmqctl cluster_status
Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]}]},{running_nodes,[rabbit@node1]}]
...done.
node2$ rabbitmqctl cluster_status
Cluster status of node rabbit@node2 ...
[{nodes,[{disc,[rabbit@node2]}]},{running_nodes,[rabbit@node2]}]
...done.
node3$ rabbitmqctl cluster_status
Cluster status of node rabbit@node3 ...
[{nodes,[{disc,[rabbit@node3]}]},{running_nodes,[rabbit@node3]}]
...done.
node2$ rabbitmqctl join_cluster --ram rabbit@node1
node3$ rabbitmqctl join_cluster rabbit@node2
node3$ rabbitmqctl cluster_status
Cluster status of node rabbit@node3 ...
[{nodes,[{disc,[rabbit@node3,rabbit@node1]},{ram,[rabbit@node2]}]},
{running_nodes,[rabbit@node2,rabbit@node1,rabbit@node3]}]
...done.
Creating a cluster
node1$ rabbitmqctl stop_app
node2$ rabbitmqctl forget_cluster_node rabbit@node1
node1$ rabbitmqctl reset
node1$ rabbitmqctl start_app
node2$ rabbitmqctl cluster_status
Cluster status of node rabbit@node2 ...
[{nodes,[{disc,[rabbit@node3]},{ram,[rabbit@node2]}]},
{running_nodes,[rabbit@node2,rabbit@node3]}]
...done.
Managing Nodes
● Stopping/starting nodes
● Removing nodes:
Solution 2: HA
HA + Queue Mirroring
RabbitMQ
Node 1
RabbitMQ
Node 2
Load Balance / Floating IP / Low TTL DNS etc.
https://github.com/asgrim/rmq-slides
Have a go yourself!
Questions?
James Titcumb
www.jamestitcumb.com
www.protected.co.uk
www.phphants.co.uk
@asgrim
Thanks for watching!

More Related Content

What's hot (20)

PPTX
Spring RabbitMQ
Martin Toshev
 
PDF
Messaging Standards and Systems - AMQP & RabbitMQ
All Things Open
 
PPTX
The RabbitMQ Message Broker
Martin Toshev
 
PDF
Distributed messaging with AMQP
Wee Keat Chin
 
PPTX
Spring RabbitMQ
Martin Toshev
 
PDF
Rabbitmq, amqp Intro - Messaging Patterns
Javier Arias Losada
 
PDF
Introduction to AMQP Messaging with RabbitMQ
Dmitriy Samovskiy
 
PDF
RabbitMQ
Lenz Gschwendtner
 
PPTX
Scaling application with RabbitMQ
Nahidul Kibria
 
ODP
Introduction To RabbitMQ
Knoldus Inc.
 
PDF
RabbitMQ Operations
Michael Klishin
 
PDF
Dissecting the rabbit: RabbitMQ Internal Architecture
Alvaro Videla
 
PDF
Messaging with amqp and rabbitmq
Selasie Hanson
 
PDF
RabbitMQ Data Ingestion
Alvaro Videla
 
PDF
RabbitMQ fairly-indepth
Wee Keat Chin
 
PDF
An update from the RabbitMQ team - Michael Klishin
RabbitMQ Summit
 
PDF
XMPP & AMQP
voluntas
 
PDF
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Javier Arias Losada
 
PDF
AMQP for phpMelb
Wee Keat Chin
 
PDF
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Paolo Negri
 
Spring RabbitMQ
Martin Toshev
 
Messaging Standards and Systems - AMQP & RabbitMQ
All Things Open
 
The RabbitMQ Message Broker
Martin Toshev
 
Distributed messaging with AMQP
Wee Keat Chin
 
Spring RabbitMQ
Martin Toshev
 
Rabbitmq, amqp Intro - Messaging Patterns
Javier Arias Losada
 
Introduction to AMQP Messaging with RabbitMQ
Dmitriy Samovskiy
 
Scaling application with RabbitMQ
Nahidul Kibria
 
Introduction To RabbitMQ
Knoldus Inc.
 
RabbitMQ Operations
Michael Klishin
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Alvaro Videla
 
Messaging with amqp and rabbitmq
Selasie Hanson
 
RabbitMQ Data Ingestion
Alvaro Videla
 
RabbitMQ fairly-indepth
Wee Keat Chin
 
An update from the RabbitMQ team - Michael Klishin
RabbitMQ Summit
 
XMPP & AMQP
voluntas
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Javier Arias Losada
 
AMQP for phpMelb
Wee Keat Chin
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Paolo Negri
 

Similar to Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014) (20)

PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
James Titcumb
 
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
James Titcumb
 
PDF
What RabbitMQ can do for you (phpnw14 Uncon)
James Titcumb
 
PDF
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
James Titcumb
 
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
James Titcumb
 
PPTX
Troubleshooting common oslo.messaging and RabbitMQ issues
Michael Klishin
 
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
James Titcumb
 
PDF
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
James Titcumb
 
PDF
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
James Titcumb
 
PDF
RabbitMQ for Perl mongers
Lenz Gschwendtner
 
PDF
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
Ontico
 
PDF
Get Started with RabbitMQ (CoderCruise 2017)
James Titcumb
 
PDF
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia
 
PDF
Aerospike Go Language Client
Sayyaparaju Sunil
 
PDF
Microblogging via XMPP
Stoyan Zhekov
 
PDF
MySQL async message subscription platform
Louis liu
 
PDF
Actor Concurrency
Alex Miller
 
PDF
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
Jervin Real
 
PDF
Symfony Performance
Paul Thrasher
 
PPTX
Ob1k presentation at Java.IL
Eran Harel
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
James Titcumb
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
James Titcumb
 
What RabbitMQ can do for you (phpnw14 Uncon)
James Titcumb
 
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
James Titcumb
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
James Titcumb
 
Troubleshooting common oslo.messaging and RabbitMQ issues
Michael Klishin
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
James Titcumb
 
Low Latency Logging with RabbitMQ (Brno PHP, CZ - 20th Sep 2014)
James Titcumb
 
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
James Titcumb
 
RabbitMQ for Perl mongers
Lenz Gschwendtner
 
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
Ontico
 
Get Started with RabbitMQ (CoderCruise 2017)
James Titcumb
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia
 
Aerospike Go Language Client
Sayyaparaju Sunil
 
Microblogging via XMPP
Stoyan Zhekov
 
MySQL async message subscription platform
Louis liu
 
Actor Concurrency
Alex Miller
 
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
Jervin Real
 
Symfony Performance
Paul Thrasher
 
Ob1k presentation at Java.IL
Eran Harel
 
Ad

More from James Titcumb (20)

PDF
Living the Best Life on a Legacy Project (phpday 2022).pdf
James Titcumb
 
PDF
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps (Bulgaria 2019)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (php[world] 2019)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps (php[world] 2019)
James Titcumb
 
PDF
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (PHP Russia 2019)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps - PHP UK 2019
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
James Titcumb
 
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
James Titcumb
 
PDF
Crafting Quality PHP Applications (PHPkonf 2018)
James Titcumb
 
PDF
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
James Titcumb
 
PDF
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
James Titcumb
 
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
James Titcumb
 
PDF
Climbing the Abstract Syntax Tree (PHP UK 2018)
James Titcumb
 
Living the Best Life on a Legacy Project (phpday 2022).pdf
James Titcumb
 
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
James Titcumb
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
James Titcumb
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
James Titcumb
 
Climbing the Abstract Syntax Tree (php[world] 2019)
James Titcumb
 
Best practices for crafting high quality PHP apps (php[world] 2019)
James Titcumb
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
James Titcumb
 
Best practices for crafting high quality PHP apps - PHP UK 2019
James Titcumb
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
James Titcumb
 
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
James Titcumb
 
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
James Titcumb
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
James Titcumb
 
Crafting Quality PHP Applications (PHPkonf 2018)
James Titcumb
 
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
James Titcumb
 
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
James Titcumb
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
James Titcumb
 
Ad

Recently uploaded (20)

PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PPTX
For my supp to finally picking supp that work
necas19388
 
PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
Rewards and Recognition (2).pdf
ethan Talor
 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
For my supp to finally picking supp that work
necas19388
 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Dealing with JSON in the relational world
Andres Almiray
 

Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)