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

James Titcumb
James TitcumbFreelance at Roave, LLC
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
1 of 63

Recommended

What RabbitMQ can do for you (phpnw14 Uncon) by
What RabbitMQ can do for you (phpnw14 Uncon)What RabbitMQ can do for you (phpnw14 Uncon)
What RabbitMQ can do for you (phpnw14 Uncon)James Titcumb
1.5K views42 slides
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015) by
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)James Titcumb
678 views83 slides
Follow the White Rabbit - Message Queues with PHP by
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPEric Rodriguez (Hiring in Lex)
13.7K views43 slides
AnyMQ, Hippie, and the real-time web by
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
4K views98 slides
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015) by
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP UK 2015)James Titcumb
1.3K views72 slides
An introduction to Raku by
An introduction to RakuAn introduction to Raku
An introduction to RakuSimon Proctor
2.9K views55 slides

More Related Content

What's hot

PL/Perl - New Features in PostgreSQL 9.0 201012 by
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012Tim Bunce
5.4K views35 slides
Application Logging in the 21st century - 2014.key by
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyTim Bunce
6.4K views65 slides
What you need to remember when you upload to CPAN by
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPANcharsbar
1.4K views66 slides
RestMQ - HTTP/Redis based Message Queue by
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueGleicon Moraes
121.4K views25 slides
Trading with opensource tools, two years later by
Trading with opensource tools, two years laterTrading with opensource tools, two years later
Trading with opensource tools, two years laterclkao
2K views38 slides
typemap in Perl/XS by
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
1.5K views88 slides

What's hot(20)

PL/Perl - New Features in PostgreSQL 9.0 201012 by Tim Bunce
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce5.4K views
Application Logging in the 21st century - 2014.key by Tim Bunce
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
Tim Bunce6.4K views
What you need to remember when you upload to CPAN by charsbar
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
charsbar1.4K views
RestMQ - HTTP/Redis based Message Queue by Gleicon Moraes
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
Gleicon Moraes121.4K views
Trading with opensource tools, two years later by clkao
Trading with opensource tools, two years laterTrading with opensource tools, two years later
Trading with opensource tools, two years later
clkao2K views
typemap in Perl/XS by charsbar
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
charsbar1.5K views
PL/Perl - New Features in PostgreSQL 9.0 by Tim Bunce
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
Tim Bunce3.7K views
Smolder @Silex by Jeen Lee
Smolder @SilexSmolder @Silex
Smolder @Silex
Jeen Lee1.1K views
PHP5.5 is Here by julien pauli
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
julien pauli13.6K views
Redis as a message queue by Brandon Lamb
Redis as a message queueRedis as a message queue
Redis as a message queue
Brandon Lamb8.7K views
Doing It Wrong with Puppet - by Puppet
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet -
Puppet8.8K views
East Bay Ruby Tropo presentation by Adam Kalsey
East Bay Ruby Tropo presentationEast Bay Ruby Tropo presentation
East Bay Ruby Tropo presentation
Adam Kalsey1.1K views
"Swoole: double troubles in c", Alexandr Vronskiy by Fwdays
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
Fwdays872 views
Mасштабирование микросервисов на Go, Matt Heath (Hailo) by Ontico
Mасштабирование микросервисов на Go, Matt Heath (Hailo)Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Ontico2.6K views
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert.... by La Cuisine du Web
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
La Cuisine du Web329 views
Node.js streaming csv downloads proxy by Ismael Celis
Node.js streaming csv downloads proxyNode.js streaming csv downloads proxy
Node.js streaming csv downloads proxy
Ismael Celis18.4K views
Php in 2013 (Web-5 2013 conference) by julien pauli
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
julien pauli2.8K views
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf by Tom Croucher
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher22.7K views

Viewers also liked

Photoshop Tutorial by
Photoshop TutorialPhotoshop Tutorial
Photoshop TutorialPuggleRat
254 views10 slides
Pkmt by
PkmtPkmt
Pkmtjenniewidianie
198 views7 slides
мојата татковина Davit by
мојата татковина Davitмојата татковина Davit
мојата татковина DavitSuzana Mladenova
484 views4 slides
Flocations by
FlocationsFlocations
Flocationspascal89
213 views7 slides
Michael Durante Western Reserve 4Q05 letter by
Michael Durante Western Reserve 4Q05 letterMichael Durante Western Reserve 4Q05 letter
Michael Durante Western Reserve 4Q05 letterMichael Durante
537 views7 slides
Print8Bit Nedir? by
Print8Bit Nedir?Print8Bit Nedir?
Print8Bit Nedir?Erdem İnanç
323 views16 slides

Viewers also liked(20)

Photoshop Tutorial by PuggleRat
Photoshop TutorialPhotoshop Tutorial
Photoshop Tutorial
PuggleRat254 views
мојата татковина Davit by Suzana Mladenova
мојата татковина Davitмојата татковина Davit
мојата татковина Davit
Suzana Mladenova484 views
Flocations by pascal89
FlocationsFlocations
Flocations
pascal89213 views
Michael Durante Western Reserve 4Q05 letter by Michael Durante
Michael Durante Western Reserve 4Q05 letterMichael Durante Western Reserve 4Q05 letter
Michael Durante Western Reserve 4Q05 letter
Michael Durante537 views
Geoportal of Wallonia : discover geographic data in Wallonia by Vincent Bombaerts
Geoportal of Wallonia : discover geographic data in WalloniaGeoportal of Wallonia : discover geographic data in Wallonia
Geoportal of Wallonia : discover geographic data in Wallonia
Vincent Bombaerts1.1K views
Turn Your Data Into Insight_WP by Scott Jones
Turn Your Data Into Insight_WPTurn Your Data Into Insight_WP
Turn Your Data Into Insight_WP
Scott Jones182 views
Liatoto na-bulgarskoto-izkustvo-2014.eng-1 by Sim Aleksiev
Liatoto na-bulgarskoto-izkustvo-2014.eng-1Liatoto na-bulgarskoto-izkustvo-2014.eng-1
Liatoto na-bulgarskoto-izkustvo-2014.eng-1
Sim Aleksiev411 views
Thomas edison research parker schwan by parksch
Thomas edison research   parker schwanThomas edison research   parker schwan
Thomas edison research parker schwan
parksch686 views
Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu... by progressive01
Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu...Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu...
Update of the Tasmanian Pacific Oysters Health Surveillance Program & Biosecu...
progressive011.4K views
"상금 1억" 꿈의 마케팅 아이디어 공모전 by Ji Hyeok Kim
"상금 1억" 꿈의 마케팅 아이디어 공모전"상금 1억" 꿈의 마케팅 아이디어 공모전
"상금 1억" 꿈의 마케팅 아이디어 공모전
Ji Hyeok Kim870 views
Poms the farmers view - David Barker by progressive01
Poms the farmers view - David BarkerPoms the farmers view - David Barker
Poms the farmers view - David Barker
progressive01728 views
Sense T - What happens when sensing happens? by progressive01
Sense T - What happens when sensing happens? Sense T - What happens when sensing happens?
Sense T - What happens when sensing happens?
progressive011.1K views

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

Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014) by
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)James Titcumb
2.2K views71 slides
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014) by
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)James Titcumb
3K views59 slides
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup by
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
25.5K views81 slides
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2... by
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...James Titcumb
445 views83 slides
PHP, RabbitMQ, and You by
PHP, RabbitMQ, and YouPHP, RabbitMQ, and You
PHP, RabbitMQ, and YouJason Lotito
4.8K views76 slides
Tatsumaki by
TatsumakiTatsumaki
TatsumakiTatsuhiko Miyagawa
12.5K views59 slides

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

Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014) by James Titcumb
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
Practical Message Queueing using RabbitMQ (Nomad PHP EU Dec 2014)
James Titcumb2.2K views
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014) by James Titcumb
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
James Titcumb3K views
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup by Kacper Gunia
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia25.5K views
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2... by James Titcumb
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHP Oxford June Meetup 2...
James Titcumb445 views
PHP, RabbitMQ, and You by Jason Lotito
PHP, RabbitMQ, and YouPHP, RabbitMQ, and You
PHP, RabbitMQ, and You
Jason Lotito4.8K views
Get Started with RabbitMQ (CoderCruise 2017) by James Titcumb
Get Started with RabbitMQ (CoderCruise 2017)Get Started with RabbitMQ (CoderCruise 2017)
Get Started with RabbitMQ (CoderCruise 2017)
James Titcumb151 views
Troubleshooting common oslo.messaging and RabbitMQ issues by Michael Klishin
Troubleshooting common oslo.messaging and RabbitMQ issuesTroubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issues
Michael Klishin11.2K views
How CPAN Testers helped me improve my module by acme
How CPAN Testers helped me improve my moduleHow CPAN Testers helped me improve my module
How CPAN Testers helped me improve my module
acme3.4K views
Use perl creating web services with xml rpc by Johnny Pork
Use perl creating web services with xml rpcUse perl creating web services with xml rpc
Use perl creating web services with xml rpc
Johnny Pork977 views
4069180 Caching Performance Lessons From Facebook by guoqing75
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
guoqing752.4K views
Facebook的缓存系统 by yiditushe
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
yiditushe1.1K views
6. hands on - open mano demonstration in remote pool of servers by videos
6. hands on - open mano demonstration in remote pool of servers6. hands on - open mano demonstration in remote pool of servers
6. hands on - open mano demonstration in remote pool of servers
videos2.1K views
Performance measurement and tuning by AOE
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE2.3K views
Deep dive in container service discovery by Docker, Inc.
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discovery
Docker, Inc.1.5K views
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery by Tatsuhiko Miyagawa
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa39.1K views
Integrating icinga2 and the HashiCorp suite by Bram Vogelaar
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
Bram Vogelaar86 views
Harmonious Development: Via Vagrant and Puppet by Achieve Internet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
Achieve Internet4.7K views
Exploiting the newer perl to improve your plugins by Marian Marinov
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your plugins
Marian Marinov934 views

More from James Titcumb

Living the Best Life on a Legacy Project (phpday 2022).pdf by
Living the Best Life on a Legacy Project (phpday 2022).pdfLiving the Best Life on a Legacy Project (phpday 2022).pdf
Living the Best Life on a Legacy Project (phpday 2022).pdfJames Titcumb
58 views66 slides
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021) by
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)James Titcumb
170 views66 slides
Climbing the Abstract Syntax Tree (Midwest PHP 2020) by
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)James Titcumb
199 views125 slides
Best practices for crafting high quality PHP apps (Bulgaria 2019) by
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)James Titcumb
254 views122 slides
Climbing the Abstract Syntax Tree (php[world] 2019) by
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)James Titcumb
160 views126 slides
Best practices for crafting high quality PHP apps (php[world] 2019) by
Best practices for crafting high quality PHP apps (php[world] 2019)Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)James Titcumb
260 views125 slides

More from James Titcumb(20)

Living the Best Life on a Legacy Project (phpday 2022).pdf by James Titcumb
Living the Best Life on a Legacy Project (phpday 2022).pdfLiving the Best Life on a Legacy Project (phpday 2022).pdf
Living the Best Life on a Legacy Project (phpday 2022).pdf
James Titcumb58 views
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021) by James Titcumb
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
Tips for Tackling a Legacy Codebase (ScotlandPHP 2021)
James Titcumb170 views
Climbing the Abstract Syntax Tree (Midwest PHP 2020) by James Titcumb
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
James Titcumb199 views
Best practices for crafting high quality PHP apps (Bulgaria 2019) by James Titcumb
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)
James Titcumb254 views
Climbing the Abstract Syntax Tree (php[world] 2019) by James Titcumb
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
James Titcumb160 views
Best practices for crafting high quality PHP apps (php[world] 2019) by James Titcumb
Best practices for crafting high quality PHP apps (php[world] 2019)Best practices for crafting high quality PHP apps (php[world] 2019)
Best practices for crafting high quality PHP apps (php[world] 2019)
James Titcumb260 views
Crafting Quality PHP Applications (PHP Joburg Oct 2019) by James Titcumb
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
James Titcumb263 views
Climbing the Abstract Syntax Tree (PHP Russia 2019) by James Titcumb
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
James Titcumb195 views
Best practices for crafting high quality PHP apps - PHP UK 2019 by James Titcumb
Best practices for crafting high quality PHP apps - PHP UK 2019Best practices for crafting high quality PHP apps - PHP UK 2019
Best practices for crafting high quality PHP apps - PHP UK 2019
James Titcumb324 views
Climbing the Abstract Syntax Tree (ScotlandPHP 2018) by James Titcumb
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
James Titcumb181 views
Best practices for crafting high quality PHP apps (ScotlandPHP 2018) by James Titcumb
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
James Titcumb322 views
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
James Titcumb637 views
Best practices for crafting high quality PHP apps (PHP South Africa 2018) by James Titcumb
Best practices for crafting high quality PHP apps (PHP South Africa 2018)Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
James Titcumb122 views
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018) by James Titcumb
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
James Titcumb133 views
Climbing the Abstract Syntax Tree (Southeast PHP 2018) by James Titcumb
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
James Titcumb233 views
Crafting Quality PHP Applications (PHPkonf 2018) by James Titcumb
Crafting Quality PHP Applications (PHPkonf 2018)Crafting Quality PHP Applications (PHPkonf 2018)
Crafting Quality PHP Applications (PHPkonf 2018)
James Titcumb209 views
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018) by James Titcumb
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
Best practices for crafting high quality PHP apps (PHP Yorkshire 2018)
James Titcumb264 views
Crafting Quality PHP Applications: an overview (PHPSW March 2018) by James Titcumb
Crafting Quality PHP Applications: an overview (PHPSW March 2018)Crafting Quality PHP Applications: an overview (PHPSW March 2018)
Crafting Quality PHP Applications: an overview (PHPSW March 2018)
James Titcumb210 views
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
James Titcumb197 views
Climbing the Abstract Syntax Tree (PHP UK 2018) by James Titcumb
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
James Titcumb520 views

Recently uploaded

PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
248 views20 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
127 views17 slides
"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
11 views34 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
41 views73 slides
Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
12 views160 slides

Recently uploaded(20)

Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10248 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays11 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56114 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...

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