SlideShare a Scribd company logo
Adding 1.21 Gigawatts 
to Applications 
with RabbitMQ 
James Titcumb 
PHPNW December 2014
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
Real world uses?
Why RabbitMQ?
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
http://localhost:15672/
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 to expect...
A word on 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 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 (PHPNW Dec 2014 Meetup)
Fetch message 
Logging Sequence 
Browser Application Log Server 
HTTP request 
JSON via AMQP 
Error! 
HTTP response 
RabbitMQ
Flexibility!
RPC
TTL
DLX
Infrastructure
Problem: SPOF
Solution 1: Clustering
Clustering 
RabbitMQ 
Node 1 
RabbitMQ 
Node 3 
RabbitMQ 
Node 2 
RabbitMQ 
Node 4 
RabbitMQ 
Node 6 
RabbitMQ 
Node 5 
Load Balance / Floating IP / Low TTL DNS etc.
Everything Replicates 
(except queues…)
RAM / Disk
Configuration...
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.
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.
Starting/Stopping Nodes
Removing 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.
Solution 2: HA
HA + Queue Mirroring 
RabbitMQ 
Node 1 
RabbitMQ 
Node 2 
Load Balance / Floating IP / Low TTL DNS etc.
Have a go yourself! 
https://github.com/asgrim/rmq-slides
Questions?
Thanks for watching! 
James Titcumb 
@asgrim

More Related Content

PDF
What RabbitMQ can do for you (phpnw14 Uncon)
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
PDF
Follow the White Rabbit - Message Queues with PHP
ZIP
AnyMQ, Hippie, and the real-time web
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
PPTX
An introduction to Raku
PDF
Redis & ZeroMQ: How to scale your application
PPT
On UnQLite
What RabbitMQ can do for you (phpnw14 Uncon)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Follow the White Rabbit - Message Queues with PHP
AnyMQ, Hippie, and the real-time web
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
An introduction to Raku
Redis & ZeroMQ: How to scale your application
On UnQLite

What's hot (20)

PDF
PL/Perl - New Features in PostgreSQL 9.0 201012
PDF
Application Logging in the 21st century - 2014.key
PDF
What you need to remember when you upload to CPAN
PDF
RestMQ - HTTP/Redis based Message Queue
PDF
Trading with opensource tools, two years later
PPT
typemap in Perl/XS
PDF
PL/Perl - New Features in PostgreSQL 9.0
PDF
Smolder @Silex
ODP
PHP5.5 is Here
PDF
Redis as a message queue
PDF
Doing It Wrong with Puppet -
PDF
East Bay Ruby Tropo presentation
PDF
"Swoole: double troubles in c", Alexandr Vronskiy
PDF
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
PDF
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
PDF
Node.js streaming csv downloads proxy
ODP
Php in 2013 (Web-5 2013 conference)
PDF
Memory Manglement in Raku
PDF
ReactPHP
PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
PL/Perl - New Features in PostgreSQL 9.0 201012
Application Logging in the 21st century - 2014.key
What you need to remember when you upload to CPAN
RestMQ - HTTP/Redis based Message Queue
Trading with opensource tools, two years later
typemap in Perl/XS
PL/Perl - New Features in PostgreSQL 9.0
Smolder @Silex
PHP5.5 is Here
Redis as a message queue
Doing It Wrong with Puppet -
East Bay Ruby Tropo presentation
"Swoole: double troubles in c", Alexandr Vronskiy
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
Node.js streaming csv downloads proxy
Php in 2013 (Web-5 2013 conference)
Memory Manglement in Raku
ReactPHP
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Ad

Viewers also liked (20)

PPTX
Photoshop Tutorial
PPTX
PPTX
мојата татковина Davit
PPTX
Flocations
PDF
Michael Durante Western Reserve 4Q05 letter
PPTX
Print8Bit Nedir?
PPTX
Geoportal of Wallonia : discover geographic data in Wallonia
PDF
Apgr8q2teachinggude2 130726032847-phpapp01
PDF
Turn Your Data Into Insight_WP
PPT
Liatoto na-bulgarskoto-izkustvo-2014.eng-1
PPT
Grigor velev-2013
PPTX
Thomas edison research parker schwan
DOCX
movie review of rush
PPTX
research brief
PPT
Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu...
PPTX
"상금 1억" 꿈의 마케팅 아이디어 공모전
PPTX
Poms the farmers view - David Barker
PPTX
Sense T - What happens when sensing happens?
PPT
Ivan yzunov-2013eng
PPTX
#Shareyouresearch - L.Benacchio
Photoshop Tutorial
мојата татковина Davit
Flocations
Michael Durante Western Reserve 4Q05 letter
Print8Bit Nedir?
Geoportal of Wallonia : discover geographic data in Wallonia
Apgr8q2teachinggude2 130726032847-phpapp01
Turn Your Data Into Insight_WP
Liatoto na-bulgarskoto-izkustvo-2014.eng-1
Grigor velev-2013
Thomas edison research parker schwan
movie review of rush
research brief
Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu...
"상금 1억" 꿈의 마케팅 아이디어 공모전
Poms the farmers view - David Barker
Sense T - What happens when sensing happens?
Ivan yzunov-2013eng
#Shareyouresearch - L.Benacchio
Ad

Similar to Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup) (20)

PDF
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
PDF
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
PDF
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
PDF
PHP, RabbitMQ, and You
KEY
PDF
RabbitMQ for Perl mongers
PDF
Get Started with RabbitMQ (CoderCruise 2017)
PPTX
Troubleshooting common oslo.messaging and RabbitMQ issues
PDF
How CPAN Testers helped me improve my module
DOC
Use perl creating web services with xml rpc
PDF
4069180 Caching Performance Lessons From Facebook
PDF
Facebook的缓存系统
PDF
6. hands on - open mano demonstration in remote pool of servers
PDF
Performance measurement and tuning
 
PDF
Deep dive in container service discovery
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
ODP
Integrating icinga2 and the HashiCorp suite
PPTX
Harmonious Development: Via Vagrant and Puppet
ODP
Exploiting the newer perl to improve your plugins
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
PHP, RabbitMQ, and You
RabbitMQ for Perl mongers
Get Started with RabbitMQ (CoderCruise 2017)
Troubleshooting common oslo.messaging and RabbitMQ issues
How CPAN Testers helped me improve my module
Use perl creating web services with xml rpc
4069180 Caching Performance Lessons From Facebook
Facebook的缓存系统
6. hands on - open mano demonstration in remote pool of servers
Performance measurement and tuning
 
Deep dive in container service discovery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Integrating icinga2 and the HashiCorp suite
Harmonious Development: Via Vagrant and Puppet
Exploiting the newer perl to improve your plugins

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)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Understanding_Digital_Forensics_Presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf

Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)

  • 1. Adding 1.21 Gigawatts to Applications with RabbitMQ James Titcumb PHPNW December 2014
  • 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
  • 12. Installing RabbitMQ (on precise64, other OSs may vary)
  • 13. 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
  • 16. Objective: Basic Queuing test_queue 1 2 3 4 5 Producer Consumer
  • 17. composer.json { "require": { "videlalvaro/php-amqplib": "2.*" } } then composer install
  • 18. Please wait, connecting... use PhpAmqpLibConnectionAMQPConnection; $connection = new AMQPConnection( 'localhost', 5672, 'guest', 'guest', '/' ); $channel = $connection->channel();
  • 19. 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');
  • 20. 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(); }
  • 23. Objective: Fanout Exchange test_exchange amq.KfgPZ3PE amq.cK5Cp3FC Consumer Consumer Producer 1 1 2 2 3 3 4 4 5 5
  • 24. 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');
  • 25. 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');
  • 27. A word on Temporary Queues Producer test_exchange Messages go nowhere
  • 29. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer BK = orange, banana, apple Consumer
  • 30. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = ORANGE BK = orange, banana, apple Consumer
  • 31. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = BANANA BK = orange, banana, apple Consumer
  • 32. Objective: Direct Exchange test_direct BK = banana, apple BK = apple Consumer Consumer Producer MESSAGE ROUTING KEY = APPLE BK = orange, banana, apple Consumer
  • 33. 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);
  • 34. 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');
  • 37. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 38. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer RED.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 39. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 40. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.GRASS.LONG BK = green.# Consumer BK = *.grass.* / *.*.long Consumer
  • 43. Fetch message Logging Sequence Browser Application Log Server HTTP request JSON via AMQP Error! HTTP response RabbitMQ
  • 45. RPC
  • 46. TTL
  • 47. DLX
  • 51. Clustering RabbitMQ Node 1 RabbitMQ Node 3 RabbitMQ Node 2 RabbitMQ Node 4 RabbitMQ Node 6 RabbitMQ Node 5 Load Balance / Floating IP / Low TTL DNS etc.
  • 55. 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.
  • 56. 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.
  • 58. Removing 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.
  • 60. HA + Queue Mirroring RabbitMQ Node 1 RabbitMQ Node 2 Load Balance / Floating IP / Low TTL DNS etc.
  • 61. Have a go yourself! https://github.com/asgrim/rmq-slides
  • 63. Thanks for watching! James Titcumb @asgrim