Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)

James Titcumb
James TitcumbFreelance at Roave, LLC
this slide is intentionally left blank
Before we begin...
Copy folder from USB to your local machine.
$ cd /path/to/the/folder/you/copied/from/usb/
$ vagrant box add asgrim/rmq-vm rmq-vm.box
$ vagrant up --no-provision
Test it in your browser...
http://192.168.33.99:15672/
@asgrim
Introducing
Practical RabbitMQ
James Titcumb
@asgrim
Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)
Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)
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?
@asgrim
What is message
queueing?
@asgrim
Photo: http://spitalfieldslife.com/2011/08/27/a-fox-in-hoxton-2/
Separation of Concerns
@asgrim
Scaling with Rabbit
RabbitMQApplication
Background processing
@asgrim
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
@asgrim
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
@asgrim
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
@asgrim
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
Background processing
@asgrim
Real world uses?
@asgrim
SOA
@asgrim
Why RabbitMQ?
@asgrim
(you need Vagrant+VirtualBox already)
Installing RabbitMQ
@asgrim
vagrant up
Copy folder from USB to your local machine.
$ cd /path/to/the/folder/you/copied/from/usb/
$ vagrant box add asgrim/rmq-vm rmq-vm.box
$ vagrant up --no-provision
Test it in your browser...
http://192.168.33.99:15672/
@asgrim
Library with Composer
composer require videlalvaro/php-amqplib
@asgrim
The Management Console
http://192.168.33.99:15672/
@asgrim
Practical
@asgrim
Objective: Basic Queuing
Producer Consumer
test_queue
1 2 3 4 5
@asgrim
Exchanges: Fanout
@asgrim
Objective: Fanout Exchange
test_exchange
amq.KfgPZ3PE
amq.cK5Cp3FC
Consumer
Consumer
Producer
1
1
2
2
3
3
4
4
5
5
@asgrim
A word on Temporary Queues
test_exchangeProducer
Messages
go nowhere
@asgrim
Exchanges: Direct
@asgrim
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
BK = orange, banana,
apple
Consumer
@asgrim
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= ORANGE
BK = orange, banana,
apple
Consumer
@asgrim
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= BANANA
BK = orange, banana,
apple
Consumer
@asgrim
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGE
ROUTING KEY
= APPLE
BK = orange, banana,
apple
Consumer
@asgrim
Exchanges: Topic
@asgrim
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
@asgrim
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
RED.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
@asgrim
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
@asgrim
Objective:
Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.GRASS.LONG
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
@asgrim
Message
Acknowledgement
@asgrim
Real World Example
@asgrim
Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)
Fetch message
Logging Sequence
ApplicationBrowser Log Server
HTTP request
JSON via AMQP
Error!
HTTP response
RabbitMQ
@asgrim
Flexibility!
@asgrim
Parallel Processing
@asgrim
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
@asgrim
Photo: © Rob Allen (akrabat) https://flic.kr/p/6wp9iz
@asgrim
RPC
@asgrim
RPC example
Producer Consumer
test_queue
1
reply_to: amq.gen-Xa2
1’
@asgrim
TTL
@asgrim
TTL - per queue message
Producer Consumer
test_queue
1 2 3 4 5
}
10s@asgrim
TTL - per message
Producer Consumer
test_queue
1 2 3 4 5
5s 3s 7s 1s 9s@asgrim
TTL - queue
Producer
test_queue
}
5s (if no consumers)
@asgrim
DLX
@asgrim
DLX
test_exchange
amq.KfgPZ3PE
Producer 1
dlx_exchange
dlx_queue
1
@asgrim
Scheduling / Delayed messages
@asgrim
Shovel
@asgrim
Priority
@asgrim
Management HTTP API
@asgrim
Infrastructure
@asgrim
Problem: SPOF
@asgrim
Solution 1: Clustering
@asgrim
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.
@asgrim
Everything Replicates
(except queues…)
@asgrim
Disk / RAM
@asgrim
Configuration...
@asgrim
/etc/rabbitmq/rabbitmq.config
[
{rabbit, [
{loopback_users, []},
{vm_memory_high_watermark, 0.8}
]}
].
@asgrim
/etc/rabbitmq/rabbitmq.config
[{{{[{{[{{}}{][[[{[{{}[[}{[[{}[][}{}}}{}}{{,},]{
[[{rabbit, [{{}[[}{,,{}[][}{[][][{}{{{{}}}}[[}{{
{{}}{loopback_users, []},[][][]{}{}{}<}{[}[][][}
[{{[{vm_memory_high_watermark, 0.8}]]{}{[[[]]{}]
{{]}[{[{{}[[}{]]{}[][,{}[][}{[][][{}.[]}{]][][]}
]...{}[][,]{.}[][}{}[[[{}{][]}{}{}[}{}{}{]{}{}}[
@asgrim
node1$ rabbitmqctl cluster_status
Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]}]},{running_nodes,[rabbit@node1]}]
...done.
Creating a cluster
@asgrim
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
@asgrim
Starting/Stopping Nodes
@asgrim
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
@asgrim
Solution 2: HA
@asgrim
HA + Queue Mirroring
RabbitMQ
Node 1
RabbitMQ
Node 2
Load Balance / Floating IP / Low TTL DNS etc.
@asgrim
One more thing...
@asgrim
Challenge!
@asgrim
Any questions? :)
https://joind.in/talk/8a46c
James Titcumb @asgrim
1 of 75

More Related Content

What's hot(20)

An introduction to RakuAn introduction to Raku
An introduction to Raku
Simon Proctor2.9K views
Perlmania_Study - CPANPerlmania_Study - CPAN
Perlmania_Study - CPAN
Jeen Lee807 views
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
Wallace Reis932 views
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
Tatsuhiko Miyagawa2.4K views
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
Denis Zhdanov2.8K views
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
Ben Schwarz16.9K views
TatsumakiTatsumaki
Tatsumaki
Tatsuhiko Miyagawa12.5K views
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
Tatsuhiko Miyagawa4K views
Introduction To MocoIntroduction To Moco
Introduction To Moco
Naoya Ito2K views
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
Workhorse Computing1.4K views
Development Principles & PhilosophyDevelopment Principles & Philosophy
Development Principles & Philosophy
François-Guillaume Ribreau11.5K views
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
Tatsuhiko Miyagawa3.1K views
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia1.8K views
Elegant concurrencyElegant concurrency
Elegant concurrency
Mosky Liu723 views
Perl dancerPerl dancer
Perl dancer
Marian Marinov1.3K views

Similar to Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)(20)

Emergency cloud serverEmergency cloud server
Emergency cloud server
Jesse Alexander10.7K views

More from James Titcumb(20)

Recently uploaded(20)

ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman152 views
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver23 views
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation23 views
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum118 views
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet48 views
CXL at OCPCXL at OCP
CXL at OCP
CXL Forum183 views

Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)