Slide 17
Slide 17 text
RabbitMQ
In Practice
use PhpAmqpLib\Connection\AMQPStreamConnection;
$conn = new AMQPStreamConnection('localhost', 5762, 'u', 'p');
$channel = $conn->channel();
$channel->queue_declare('default', 0, 0, 0, 0);
$cb = function($msg) {
$data = json_decode($msg->body, true); $to = $data['to'];
$message = wordwrap($data['message'], 70, "PHP_EOL");
$headers = 'From: worker.local';
mail($to, 'Message', $message, $headers);
$msg->ack();
};
$channel->basic_consume('default', '', 0, 0, 0, 0, $cb);
while(count($channel->callbacks))
$channel->wait();
The first step is to create a
queue and attach at least one
worker that can process
messages on that queue.
Queues are created
dynamically upon their
first reference.