SlideShare a Scribd company logo
What RabbitMQ 
Can Do For You 
James Titcumb 
PHPNW14 Unconference
Who is this guy? 
James Titcumb 
www.jamestitcumb.com 
www.protected.co.uk 
www.phphants.co.uk 
@asgrim
What is message 
queueing?
Separation of Concerns
Scaling with Rabbit 
Application RabbitMQ 
Background processing
Scaling with Rabbit 
Application RabbitMQ 
Background processing 
Background processing
Scaling with Rabbit 
Application RabbitMQ 
Background processing 
Background processing 
Background processing
Scaling with Rabbit 
Application RabbitMQ 
Background processing 
Background processing 
Background processing 
Background processing
Scaling with Rabbit 
Application RabbitMQ 
Background processing 
Background processing 
Background processing 
Background processing 
Background processing
Some real world uses?
Installing RabbitMQ 
(on precise64, other OSs may vary)
Using Apt 
● 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
What RabbitMQ can do for you (phpnw14 Uncon)
Basic Message Queuing
Objective: Basic Queuing 
test_queue 
1 2 3 4 5 
Producer Consumer
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 RabbitMQ can do for you (phpnw14 Uncon)
Temporary Queues 
Producer test_exchange 
Messages 
go nowhere
Exchanges: Direct
Objective: Direct Exchange 
test_direct 
BK = banana, apple 
BK = apple 
Consumer 
Consumer 
Producer 
BK = orange, banana, 
apple 
Consumer
Objective: Direct Exchange 
test_direct 
BK = banana, apple 
BK = apple 
Consumer 
Consumer 
Producer 
MESSAGE 
ROUTING KEY 
= ORANGE 
BK = orange, banana, 
apple 
Consumer
Objective: Direct Exchange 
test_direct 
BK = banana, apple 
BK = apple 
Consumer 
Consumer 
Producer 
MESSAGE 
ROUTING KEY 
= BANANA 
BK = orange, banana, 
apple 
Consumer
Objective: Direct Exchange 
test_direct 
BK = banana, apple 
BK = apple 
Consumer 
Consumer 
Producer 
MESSAGE 
ROUTING KEY 
= APPLE 
BK = orange, banana, 
apple 
Consumer
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 RabbitMQ can do for you (phpnw14 Uncon)
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
Have a go yourself! 
https://github.com/asgrim/rmq-slides
Questions?
Thanks for watching! 
James Titcumb 
@asgrim

More Related Content

PDF
PHP, RabbitMQ, and You
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
PPTX
PPTX
Design patterns as power of programing
ODP
PHP Tips for certification - OdW13
KEY
Zend Framework Study@Tokyo #2
ODP
PHP5.5 is Here
PDF
Diving into HHVM Extensions (php[tek] 2016)
PHP, RabbitMQ, and You
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
Design patterns as power of programing
PHP Tips for certification - OdW13
Zend Framework Study@Tokyo #2
PHP5.5 is Here
Diving into HHVM Extensions (php[tek] 2016)

What's hot (20)

PDF
The new features of PHP 7
PDF
Quick tour of PHP from inside
PDF
関西PHP勉強会 php5.4つまみぐい
PPTX
PDF
Code Generation in PHP - PHPConf 2015
KEY
Good Evils In Perl (Yapc Asia)
PDF
07 Introduction to PHP #burningkeyboards
PDF
Smolder @Silex
PPS
Php security3895
PDF
PHP7 is coming
PPTX
PHP Optimization
PPTX
非同期処理の通知処理 with Tatsumaki
PDF
Key features PHP 5.3 - 5.6
PDF
PHP Conference Asia 2016
PDF
PHP7 - Scalar Type Hints & Return Types
PDF
OSDC.TW - Gutscript for PHP haters
PPT
Introduction to PHP
KEY
Intermediate PHP
PDF
Coffeescript - Getting Started
PDF
Zend Certification Preparation Tutorial
The new features of PHP 7
Quick tour of PHP from inside
関西PHP勉強会 php5.4つまみぐい
Code Generation in PHP - PHPConf 2015
Good Evils In Perl (Yapc Asia)
07 Introduction to PHP #burningkeyboards
Smolder @Silex
Php security3895
PHP7 is coming
PHP Optimization
非同期処理の通知処理 with Tatsumaki
Key features PHP 5.3 - 5.6
PHP Conference Asia 2016
PHP7 - Scalar Type Hints & Return Types
OSDC.TW - Gutscript for PHP haters
Introduction to PHP
Intermediate PHP
Coffeescript - Getting Started
Zend Certification Preparation Tutorial
Ad

Viewers also liked (12)

PDF
Detrás del Backend [phpDay 2015]
PDF
PHP Barcelona Monthly Talk Feb 2015
PPTX
Dealing with fear in legacy projects #PHPDS15
PDF
Joomla!day2013 Albacete Spain, Responsive, Adaptive y la tundra
PPT
Gearman and asynchronous processing in PHP applications
PDF
PHPBarcelona Conference - Optimización aplicaciones PHP - Client side
PDF
Ecosistema de desarrollo en PHP con Docker y Ansible
PDF
Steganography: Hiding your secrets with PHP
PDF
From Legacy to DDD in PHP | Tech Talks | Privalia
PDF
RabbitMQ y Symfony
PPTX
Implementing DDD Concepts in PHP
PDF
How to Become a Thought Leader in Your Niche
Detrás del Backend [phpDay 2015]
PHP Barcelona Monthly Talk Feb 2015
Dealing with fear in legacy projects #PHPDS15
Joomla!day2013 Albacete Spain, Responsive, Adaptive y la tundra
Gearman and asynchronous processing in PHP applications
PHPBarcelona Conference - Optimización aplicaciones PHP - Client side
Ecosistema de desarrollo en PHP con Docker y Ansible
Steganography: Hiding your secrets with PHP
From Legacy to DDD in PHP | Tech Talks | Privalia
RabbitMQ y Symfony
Implementing DDD Concepts in PHP
How to Become a Thought Leader in Your Niche
Ad

Similar to What RabbitMQ can do for you (phpnw14 Uncon) (20)

PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
PDF
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
PDF
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
PDF
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
KEY
PDF
Get Started with RabbitMQ (CoderCruise 2017)
PDF
RabbitMQ for Perl mongers
PDF
13 PHPUnit #burningkeyboards
PDF
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
PDF
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
PPTX
An introduction to Raku
KEY
Perl Web Client
PDF
AMS Node Meetup December presentation Phusion Passenger
PDF
4069180 Caching Performance Lessons From Facebook
PDF
Continuous deployment of puppet modules
ODP
Exploiting the newer perl to improve your plugins
PDF
Performance measurement and tuning
 
PDF
Perl web app 테스트전략
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Get Started with RabbitMQ (CoderCruise 2017)
RabbitMQ for Perl mongers
13 PHPUnit #burningkeyboards
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
An introduction to Raku
Perl Web Client
AMS Node Meetup December presentation Phusion Passenger
4069180 Caching Performance Lessons From Facebook
Continuous deployment of puppet modules
Exploiting the newer perl to improve your plugins
Performance measurement and tuning
 
Perl web app 테스트전략

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
Programs and apps: productivity, graphics, security and other tools
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The AUB Centre for AI in Media Proposal.docx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology

What RabbitMQ can do for you (phpnw14 Uncon)

  • 1. What RabbitMQ Can Do For You James Titcumb PHPNW14 Unconference
  • 2. Who is this guy? James Titcumb www.jamestitcumb.com www.protected.co.uk www.phphants.co.uk @asgrim
  • 3. What is message queueing?
  • 5. Scaling with Rabbit Application RabbitMQ Background processing
  • 6. Scaling with Rabbit Application RabbitMQ Background processing Background processing
  • 7. Scaling with Rabbit Application RabbitMQ Background processing Background processing Background processing
  • 8. Scaling with Rabbit Application RabbitMQ Background processing Background processing Background processing Background processing
  • 9. Scaling with Rabbit Application RabbitMQ Background processing Background processing Background processing Background processing Background processing
  • 11. Installing RabbitMQ (on precise64, other OSs may vary)
  • 12. Using Apt ● 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
  • 15. Objective: Basic Queuing test_queue 1 2 3 4 5 Producer Consumer
  • 16. composer.json { "require": { "videlalvaro/php-amqplib": "2.*" } } then composer install
  • 17. Please wait, connecting... use PhpAmqpLibConnectionAMQPConnection; $connection = new AMQPConnection( 'localhost', 5672, 'guest', 'guest', '/' ); $channel = $connection->channel();
  • 18. 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');
  • 19. 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(); }
  • 22. Objective: Fanout Exchange test_exchange amq.KfgPZ3PE amq.cK5Cp3FC Consumer Consumer Producer 1 1 2 2 3 3 4 4 5 5
  • 23. 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');
  • 24. 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');
  • 26. Temporary Queues Producer test_exchange Messages go nowhere
  • 28. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer BK = orange, banana, apple Consumer
  • 29. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = ORANGE BK = orange, banana, apple Consumer
  • 30. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = BANANA BK = orange, banana, apple Consumer
  • 31. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = APPLE BK = orange, banana, apple Consumer
  • 32. 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);
  • 33. 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');
  • 36. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 37. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer RED.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 38. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 39. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.GRASS.LONG BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 40. Have a go yourself! https://github.com/asgrim/rmq-slides
  • 42. Thanks for watching! James Titcumb @asgrim