SlideShare a Scribd company logo
Adding 1.21 Gigawatts to
Applications with RabbitMQ
James Titcumb
Dutch PHP Conference 2015
James Titcumb
www.jamestitcumb.com
www.roave.com
www.phphants.co.uk
www.phpsouthcoast.co.uk
@asgrim
Who is this guy?
What is a message?
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
Real world uses?
SOA
Why RabbitMQ?
https://github.com/asgrim/rmq-slides
Follow along here...
(on trusty64 Vagrant, 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/
http://localhost:15672/
http://localhost:15672/
http://localhost:15672/
http://localhost:15672/
Basic Message Queue
Objective: Basic Queuing
Producer Consumer
test_queue
1 2 3 4 5
composer.json
composer require videlalvaro/php-amqplib
Approved
Please wait, connecting...
1 use PhpAmqpLibConnectionAMQPConnection;
2
3 $connection = new AMQPConnection(
4 'localhost', 5672, 'guest', 'guest', '/');
5
6 $channel = $connection->channel();
basic/producer.php
1 use PhpAmqpLibMessageAMQPMessage;
2
3 $channel->queue_declare(
4 'test_queue', false, true, false, false);
5
6 $message = new AMQPMessage('my test message');
7 $channel->basic_publish($message, '', 'test_queue');
basic/consumer.php
1 $channel->basic_consume(
2 'test_queue', '', false, true, false, false,
3 function(AMQPMessage $message) {
4 echo $message->body . "n";
5 });
6
7 while (count($channel->callbacks))
8 $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
1 use PhpAmqpLibMessageAMQPMessage;
2
3 $channel->exchange_declare(
4 'test_exchange', 'fanout', false, false, false);
5
6 $message = new AMQPMessage('test msg #' . $id);
7 $channel->basic_publish($message, 'test_exchange');
fanout/producer.php
fanout/consumer.php
1 $q = $channel->queue_declare(
2 '', false, false, false, true);
3 $queue_name = $q[0];
4
5 $channel->exchange_declare(
6 'test_exchange', 'fanout', false, false, false);
7 $channel->queue_bind($queue_name, 'test_exchange');
What to expect...
A word on Temporary Queues
test_exchangeProducer
Messages
go nowhere
Exchanges: Direct
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
BK = orange, banana,
apple
Consumer
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= ORANGE
BK = orange, banana,
apple
Consumer
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= BANANA
BK = orange, banana,
apple
Consumer
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= APPLE
BK = orange, banana,
apple
Consumer
direct/producer.php
1 $channel->exchange_declare(
2 'test_direct', 'fanout', false, false, false);
3
4 $messageContent = 'test msg, key=' . $routingKey;
5 $message = new AMQPMessage($messageContent);
6 $channel->basic_publish(
7 $message, 'test_direct', $routingKey);
direct/consumer.php
1 $q = $channel->queue_declare('', false, false, false, true);
2 $queue_name = $q[0];
3 $channel->exchange_declare(
4 'test_direct', 'direct', false, false, false);
5
6 // Bind for each routing key we want (BINDING KEY)
7 $channel->queue_bind($queue_name, 'test_direct', 'apple');
8 $channel->queue_bind($queue_name, 'test_direct', 'orange');
9 $channel->queue_bind($queue_name, 'test_direct', 'banana');
What to expect...
Exchanges: Topic
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
RED.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.GRASS.LONG
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
Real World Example
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Fetch message
Logging Sequence
ApplicationBrowser Log Server
HTTP request
JSON via AMQP
Error!
HTTP response
RabbitMQ
Flexibility!
Parallel Processing
test_exchange
amq.KfgPZ3PE
amq.cK5Cp3FC
Consumer
Producer
1
1
2
2
3
3
4
4
5
5
Consumer
Consumer
Consumer
Consumer
Consumer
Consumer
Consumer
Parallel Processing
Message
Acknowledgement
1 $channel->basic_consume(
2 'test_queue', '', false, false, false, false,
3 function(AMQPMessage $message) {
4 echo $message->body . "n";
5 throw new Exception('oh noes!!!');
6
7 $channel = $message->delivery_info['channel'];
8 $tag = $message->delivery_info['delivery_tag'];
9 $channel->basic_ack($tag);
10 });
Message Acknowledgement
RPC
RPC example
Producer Consumer
test_queue
1
reply_to: amq.gen-Xa2
1’
TTL
TTL - per queue message
Producer Consumer
test_queue
1 2 3 4 5
}
10s
TTL - per message
Producer Consumer
test_queue
1 2 3 4 5
5s 3s 7s 1s 9s
TTL - queue
Producer
test_queue
}
5s (if no consumers)
DLX
DLX
test_exchange
amq.KfgPZ3PE
Producer 1
dlx_exchange
dlx_queue
1
Scheduling / Delayed messages
Priority
http://tryrabbitmq.com/
Infrastructure
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.
Everything Replicates
(except queues…)
Disk / RAM
Configuration...
/etc/rabbitmq/rabbitmq.config
[
{rabbit, [
{loopback_users, []},
{vm_memory_high_watermark, 0.8}
]}
].
/etc/rabbitmq/rabbitmq.config
[{{{[{{[{{}}{][[[{[{{}[[}{[[{}[][}{}}}{}}{{,},]{
[[{rabbit, [{{}[[}{,,{}[][}{[][][{}{{{{}}}}[[}{{
{{}}{loopback_users, []},[][][]{}{}{}<}{[}[][][}
[{{[{vm_memory_high_watermark, 0.8}]]{}{[[[]]{}]
{{]}[{[{{}[[}{]]{}[][,{}[][}{[][][{}.[]}{]][][]}
]...{}[][,]{.}[][}{}[[[{}{][]}{}{}[}{}{}{]{}{}}[
node1$ rabbitmqctl cluster_status
Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]}]},{running_nodes,[rabbit@node1]}]
...done.
Creating a cluster
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
Starting/Stopping Nodes
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.
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
That link again...
Any questions? :)
https://joind.in/14253
James Titcumb @asgrim

More Related Content

PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
PDF
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
PDF
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
PPTX
PHP Optimization
PDF
CRUFT! - Peter Kriens, President, aQute
PDF
Profiling php5 to php7
PPT
typemap in Perl/XS
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
PHP Optimization
CRUFT! - Peter Kriens, President, aQute
Profiling php5 to php7
typemap in Perl/XS

What's hot (20)

PPT
Php optimization
ODP
ODP
PHP Tips for certification - OdW13
PDF
Artificial Neural Network in a Tic Tac Toe Symfony Console Application - Symf...
PPT
On UnQLite
ODP
Php in 2013 (Web-5 2013 conference)
PPTX
Streams, sockets and filters oh my!
PDF
Php7 extensions workshop
KEY
Zend Framework Study@Tokyo #2
PDF
Symfony live 2017_php7_performances
PDF
Understanding PHP objects
PDF
SymfonyCon 2017 php7 performances
PDF
PHP 7 performances from PHP 5
PDF
Mysqlnd, an unknown powerful PHP extension
PDF
Building Custom PHP Extensions
PDF
uerj201212
ODP
How Xslate Works
PDF
Create your own PHP extension, step by step - phpDay 2012 Verona
PDF
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
ODP
Exploiting the newer perl to improve your plugins
Php optimization
PHP Tips for certification - OdW13
Artificial Neural Network in a Tic Tac Toe Symfony Console Application - Symf...
On UnQLite
Php in 2013 (Web-5 2013 conference)
Streams, sockets and filters oh my!
Php7 extensions workshop
Zend Framework Study@Tokyo #2
Symfony live 2017_php7_performances
Understanding PHP objects
SymfonyCon 2017 php7 performances
PHP 7 performances from PHP 5
Mysqlnd, an unknown powerful PHP extension
Building Custom PHP Extensions
uerj201212
How Xslate Works
Create your own PHP extension, step by step - phpDay 2012 Verona
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
Exploiting the newer perl to improve your plugins
Ad

Viewers also liked (20)

PDF
Sporting &amp; buttonpath limited bruma
PPT
Ipc parents presentation_(1)рус
PPT
Casutadinoala
PPT
The Crisis of Mediators? Science Communication in the Digital Age
PPT
Kiril mitovski-2014-1
PDF
O recrutamento de_trabalhador_publico
PPTX
Slide show intro
PPT
Fitness 4 life
PDF
Projeto de Lei n.º 363/XIII-2.ª
PPT
Liatoto na-bulgarskoto-izkustvo-2014-1
PPTX
International Payments add-on for SAP Business One
PPTX
6 frederick
PPTX
4 ginna laport
PPTX
Different dialects
DOCX
Jacobcastillo20920329
DOCX
Actualizacion del kernel en linux
PPTX
Fany
DOCX
แนวข้อสอบเทคโนโลยี่เบิ้องต้นนักเรียนนายสิบตำรวจ
PPT
Vixra grigorova-2013eng
Sporting &amp; buttonpath limited bruma
Ipc parents presentation_(1)рус
Casutadinoala
The Crisis of Mediators? Science Communication in the Digital Age
Kiril mitovski-2014-1
O recrutamento de_trabalhador_publico
Slide show intro
Fitness 4 life
Projeto de Lei n.º 363/XIII-2.ª
Liatoto na-bulgarskoto-izkustvo-2014-1
International Payments add-on for SAP Business One
6 frederick
4 ginna laport
Different dialects
Jacobcastillo20920329
Actualizacion del kernel en linux
Fany
แนวข้อสอบเทคโนโลยี่เบิ้องต้นนักเรียนนายสิบตำรวจ
Vixra grigorova-2013eng
Ad

Similar to Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015) (20)

PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
PDF
What RabbitMQ can do for you (phpnw14 Uncon)
PDF
Get Started with RabbitMQ (CoderCruise 2017)
PDF
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
PDF
PHP, RabbitMQ, and You
PPTX
An introduction to Raku
PDF
Fewer cables
PDF
Performance measurement and tuning
 
PDF
Head in the Clouds: Testing Infra as Code - Config Management 2020
PDF
Innovative Specifications for Better Performance Logging and Monitoring
PDF
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
KEY
PDF
Unit Testing Lots of Perl
PDF
Modern Web Security, Lazy but Mindful Like a Fox
PPTX
Node.js primer
PPTX
Scaling application with RabbitMQ
PPTX
Php on the desktop and php gtk2
PDF
East Bay Ruby Tropo presentation
PDF
Living With Legacy Code
KEY
Puppet for dummies - PHPBenelux UG edition
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
What RabbitMQ can do for you (phpnw14 Uncon)
Get Started with RabbitMQ (CoderCruise 2017)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
PHP, RabbitMQ, and You
An introduction to Raku
Fewer cables
Performance measurement and tuning
 
Head in the Clouds: Testing Infra as Code - Config Management 2020
Innovative Specifications for Better Performance Logging and Monitoring
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Unit Testing Lots of Perl
Modern Web Security, Lazy but Mindful Like a Fox
Node.js primer
Scaling application with RabbitMQ
Php on the desktop and php gtk2
East Bay Ruby Tropo presentation
Living With Legacy Code
Puppet for dummies - PHPBenelux UG edition

More from James Titcumb (20)

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

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced IT Governance
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Machine learning based COVID-19 study performance prediction
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
Advanced IT Governance
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
CIFDAQ's Market Insight: SEC Turns Pro Crypto
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)

Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)