workerman / rabbitmq
Asynchronous rabbitmq client for PHP based on workerman.
Installs: 6 520
Dependents: 5
Suggesters: 0
Security: 0
Stars: 35
Watchers: 6
Forks: 8
Open Issues: 4
Requires
- bunny/bunny: ^0.5
- psr/log: ^1.0 || ^2.0 || ^3.0
- workerman/workerman: >=3.3.0
README
Asynchronous rabbitmq client for PHP based on workerman.
Install
composer require workerman/rabbitmq
Examples
receive.php
<?php use Bunny\Channel; use Bunny\Message; use Workerman\Worker; use Workerman\RabbitMQ\Client; require __DIR__ . '/vendor/autoload.php'; $worker = new Worker(); $worker->onWorkerStart = function() { (new Client())->connect()->then(function (Client $client) { return $client->channel(); })->then(function (Channel $channel) { return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) { return $channel; }); })->then(function (Channel $channel) { echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; $channel->consume( function (Message $message, Channel $channel, Client $client) { echo " [x] Received ", $message->content, "\n"; }, 'hello', '', false, true ); }); }; Worker::runAll();
Run command php receive.php start
.
send.php
<?php use Bunny\Channel; use Bunny\Message; use Workerman\Worker; use Workerman\RabbitMQ\Client; require __DIR__ . '/vendor/autoload.php'; $worker = new Worker(); $worker->onWorkerStart = function() { (new Client())->connect()->then(function (Client $client) { return $client->channel(); })->then(function (Channel $channel) { return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) { return $channel; }); })->then(function (Channel $channel) { echo " [x] Sending 'Hello World!'\n"; return $channel->publish('Hello World!', [], '', 'hello')->then(function () use ($channel) { return $channel; }); })->then(function (Channel $channel) { echo " [x] Sent 'Hello World!'\n"; $client = $channel->getClient(); return $channel->close()->then(function () use ($client) { return $client; }); })->then(function (Client $client) { $client->disconnect(); }); }; Worker::runAll();
Run command php send.php start
.