View
451
Download
0
Category
Preview:
DESCRIPTION
RabbitMQ is a message broker – an application that allows communication between applications by way of a message queuing system. In this talk, we look at some of the basic concepts of RabbitMQ and how it can help effectively scale your applications. These slides are for the lightning talk I gave at Nomad PHP on 22nd May 2014.
Citation preview
What RabbitMQ Can Do For You
James TitcumbNomad PHP Lightning Talk
May 2014
Who is this guy?
James Titcumb
www.jamestitcumb.com
www.protected.co.uk
www.phphants.co.uk
@asgrim
What is message queuing?
Separate applications
Low cost parallelisation
Basic Example
Publisher
queue
Consumer
Based on: http://www.rabbitmq.com/tutorials/tutorial-one-php.html
Exchanges
Based on: http://www.rabbitmq.com/tutorials/tutorial-three-php.html
queue1
Publisher
Publisher
Publisher
Publisher
Exchange
queue2
Consumer
Consumer
Consumer
Exchanges: Direct
Based on: http://www.rabbitmq.com/tutorials/tutorial-four-php.html
fruit
Exchange
vegetable
Fruit consumer
Veg consumer
Fruit consumerPublisher
routing key: fruit
routing key: vegetable
Exchanges: Topic
Based on: http://www.rabbitmq.com/tutorials/tutorial-five-php.html
*.fruit
Exchange
green.*
Fruit consumer
Green consumer
Veg consumerPublisher
routing key: green.fruit
routing key: green.vegetable
*.vegetable
Real World Uses
● Fast logging solution● Sending emails● Sending SMS● Background processing (e.g. analysing data)
composer.json
{
"require": {
"videlalvaro/php-amqplib": "2.*"
}
}
Set up the channel
use PhpAmqpLib\Connection\AMQPConnection;
$connection = new AMQPConnection(
'localhost', 5672, 'guest', 'guest', '/');
$channel = $connection->channel();
$channel->queue_declare('my_queue', /* params... */);
$channel->exchange_declare(
'my_exchange', 'fanout', /* params... */);
$channel->queue_bind('my_queue', 'my_exchange');
Basic Publishing Example
use PhpAmqpLib\Message\AMQPMessage;
$content = 'Hello world';
$message = new AMQPMessage($content);
$channel->basic_publish($message);
Basic Consumer Example
use PhpAmqpLib\Message\AMQPMessage;
$channel->basic_consume(
'my_queue',
/* some more parameters */
function (AMQPMessage $message) {
echo $message->body;
}
);
Questions?
Thank you!
James Titcumb
www.jamestitcumb.com
www.protected.co.uk
www.phphants.co.uk
@asgrim
Please feedback!
https://joind.in/11350
Recommended