What RabbitMQ can do for you (phpnw14 Uncon)
-
Upload
james-titcumb -
Category
Technology
-
view
564 -
download
4
description
Transcript of What RabbitMQ can do for you (phpnw14 Uncon)
![Page 1: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/1.jpg)
What RabbitMQCan Do For You
James TitcumbPHPNW14 Unconference
![Page 2: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/2.jpg)
James Titcumbwww.jamestitcumb.comwww.protected.co.ukwww.phphants.co.uk@asgrim
Who is this guy?
![Page 3: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/3.jpg)
What is message queueing?
![Page 4: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/4.jpg)
Separation of Concerns
![Page 5: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/5.jpg)
Scaling with Rabbit
RabbitMQApplication
Background processing
![Page 6: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/6.jpg)
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
![Page 7: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/7.jpg)
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
![Page 8: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/8.jpg)
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
![Page 9: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/9.jpg)
Scaling with Rabbit
RabbitMQApplication
Background processing
Background processing
Background processing
Background processing
Background processing
![Page 10: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/10.jpg)
Some real world uses?
![Page 11: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/11.jpg)
(on precise64, other OSs may vary)
Installing RabbitMQ
![Page 12: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/12.jpg)
● add apt repo○ deb http://www.rabbitmq.com/debian/ testing main
● add signing key○ http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
● apt-get update● apt-get install rabbitmq-server● rabbitmq-plugins enable rabbitmq_management● sudo service rabbitmq-server restart
Using Apt
![Page 13: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/13.jpg)
![Page 14: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/14.jpg)
Basic Message Queuing
![Page 15: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/15.jpg)
Objective: Basic Queuing
Producer Consumer
test_queue
1 2 3 4 5
![Page 16: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/16.jpg)
composer.json{
"require": {
"videlalvaro/php-amqplib": "2.*"
}
}
then composer install
![Page 17: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/17.jpg)
Please wait, connecting...use PhpAmqpLib\Connection\AMQPConnection;
$connection = new AMQPConnection(
'localhost',
5672,
'guest',
'guest',
'/'
);
$channel = $connection->channel();
![Page 18: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/18.jpg)
basic/producer.phpuse PhpAmqpLib\Message\AMQPMessage;
$channel->queue_declare(
'test_queue',
false,
true,
false, false);
$message = new AMQPMessage('my test message');
$channel->basic_publish($message, '', 'test_queue');
![Page 19: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/19.jpg)
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();
}
![Page 20: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/20.jpg)
What to expect...
![Page 21: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/21.jpg)
Exchanges: Fanout
![Page 22: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/22.jpg)
Objective: Fanout Exchange
test_exchange
amq.KfgPZ3PE
amq.cK5Cp3FC
Consumer
Consumer
Producer
1
1
2
2
3
3
4
4
5
5
![Page 23: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/23.jpg)
fanout/producer.phpuse PhpAmqpLib\Message\AMQPMessage;
$channel->exchange_declare(
'test_exchange',
'fanout',
false, false, false);
$message = new AMQPMessage('my test message #' . $id);
$channel->basic_publish($message, 'test_exchange');
![Page 24: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/24.jpg)
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');
![Page 25: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/25.jpg)
![Page 26: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/26.jpg)
Temporary Queues
test_exchangeProducerMessages
go nowhere
![Page 27: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/27.jpg)
Exchanges: Direct
![Page 28: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/28.jpg)
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
BK = orange, banana, apple
Consumer
![Page 29: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/29.jpg)
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGEROUTING KEY= ORANGE
BK = orange, banana, apple
Consumer
![Page 30: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/30.jpg)
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGEROUTING KEY= BANANA
BK = orange, banana, apple
Consumer
![Page 31: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/31.jpg)
Objective: Direct Exchange
test_direct
BK = apple
BK = banana, apple
Consumer
Consumer
Producer
MESSAGEROUTING KEY= APPLE
BK = orange, banana, apple
Consumer
![Page 32: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/32.jpg)
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);
![Page 33: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/33.jpg)
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');
![Page 34: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/34.jpg)
![Page 35: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/35.jpg)
Exchanges: Topic
![Page 36: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/36.jpg)
Objective:Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
ProducerBK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
![Page 37: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/37.jpg)
Objective:Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
RED.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
![Page 38: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/38.jpg)
Objective:Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.VEGETABLE
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
![Page 39: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/39.jpg)
Objective:Topic Exchange
test_topic
BK = *.vegetable
BK = #
Consumer
Consumer
Producer
GREEN.GRASS.LONG
BK = green.#
Consumer
BK = *.grass.* / *.*.long
Consumer
![Page 40: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/40.jpg)
https://github.com/asgrim/rmq-slides
Have a go yourself!
![Page 41: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/41.jpg)
Questions?
![Page 42: What RabbitMQ can do for you (phpnw14 Uncon)](https://reader036.fdocuments.us/reader036/viewer/2022062419/55829492d8b42ac9798b559a/html5/thumbnails/42.jpg)
James Titcumb@asgrim
Thanks for watching!