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.
8. Exchanges: Direct
Based on: http://www.rabbitmq.com/tutorials/tutorial-four-php.html
fruit
Exchange
vegetable
Fruit consumer
Veg consumer
Fruit consumer
Publisher
routing key: fruit
routing key: vegetable
9. Exchanges: Topic
Based on: http://www.rabbitmq.com/tutorials/tutorial-five-php.html
*.fruit
Exchange
green.*
Fruit consumer
Green consumer
Veg consumer
Publisher
routing key: green.fruit
routing key: green.vegetable
*.vegetable
10. Real World Uses
● Fast logging solution
● Sending emails
● Sending SMS
● Background processing (e.g. analysing data)
13. Set up the channel
use PhpAmqpLibConnectionAMQPConnection;
$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');
14. Basic Publishing Example
use PhpAmqpLibMessageAMQPMessage;
$content = 'Hello world';
$message = new AMQPMessage($content);
$channel->basic_publish($message);
15. Basic Consumer Example
use PhpAmqpLibMessageAMQPMessage;
$channel->basic_consume(
'my_queue',
/* some more parameters */
function (AMQPMessage $message) {
echo $message->body;
}
);