Closed WyriHaximus closed 4 months ago
Non-Breaking Changes:
Client
Channel
final
react/event-loop
react/socket
react/stream
Breaking changes:
react/promise
<?php
-use Bunny\Async\Client; +use Bunny\Client; -use React\EventLoop\Factory;
require dirname(DIR, 2) . '/vendor/autoload.php';
-$loop = Factory::create();
-(new Client($loop))->connect(); +$client = new Client();
-$loop->run();
* Merged `Async` and `Sync` clients into `Client` utilizing fibers through [`react/async`](https://reactphp.org/async/) ### Sync `receive.php`: ```diff <?php use Bunny\Channel; use Bunny\Client; use Bunny\Message; require dirname(__DIR__, 2) . '/vendor/autoload.php'; -$client = (new Client())->connect(); +$client = new Client(); $channel = $client->channel(); $channel->queueDeclare('hello', false, false, false, false); echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; -$channel->run( +$channel->consume( function (Message $message, Channel $channel) { echo " [x] Received ", $message->content, "\n"; }, 'hello', '', false, true, );
send.php:
send.php
<?php use Bunny\Client; require dirname(__DIR__, 2) . '/vendor/autoload.php'; -$client = (new Client())->connect(); +$client = new Client(); $channel = $client->channel(); $channel->queueDeclare('hello', false, false, false, false); $channel->close(); $channel->publish('Hello World!', [], '', 'hello'); echo " [x] Sent 'Hello World!'\n"; $channel->close(); $client->disconnect();
receive-async.php:
receive-async.php
<?php use Bunny\Channel; -use Bunny\Async\Client; +use Bunny\Client; use Bunny\Message; -use React\EventLoop\Factory; require dirname(__DIR__, 2) . '/vendor/autoload.php'; -$loop = Factory::create(); -(new Client($loop))->connect() +$client = new Client(); -->then(function (Client $client) { - return $client->channel(); -}) +$channel = $client->channel(); -->then(function (Channel $channel) { - return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) { - return $channel; - }); -}) +$channel->queueDeclare('hello', false, false, false, false); -->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 - ); -}); +echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; +$channel->consume( + function (Message $message, Channel $channel) { + echo " [x] Received ", $message->content, "\n"; + }, + 'hello', + '', + false, + true, +); -$loop->run();
send-async.php:
send-async.php
<?php -use Bunny\Channel; -use Bunny\Async\Client; +use Bunny\Client; -use React\EventLoop\Factory; require dirname(__DIR__, 2) . '/vendor/autoload.php'; -$loop = Factory::create(); -(new Client($loop))->connect() +$client = new Client(); -->then(function (Client $client) { - return $client->channel(); -}) +$channel = $client->channel(); -->then(function (Channel $channel) { - return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) { - return $channel; - }); -}) +$channel->queueDeclare('hello', false, false, false, false); -->then(function (Channel $channel) { - echo " [x] Sending 'Hello World!'\n"; - return $channel->publish('Hello World!', [], '', 'hello')->then(function () use ($channel) { - return $channel; - }); -}) +$channel->publish('Hello World!', [], '', 'hello'); -->then(function (Channel $channel) { - echo " [x] Sent 'Hello World!'\n"; - $client = $channel->getClient(); - return $channel->close()->then(function () use ($client) { - return $client; - }); -}) +echo " [x] Sent 'Hello World!'\n"; +$channel->close(); -->then(function (Client $client) { - $client->disconnect(); -}); +$client->disconnect();
string $queue
string $exchange
use Bunny\Channel; use Bunny\Client; use Bunny\Message;
$client = new Client(); $channel = $client->channel();
$channel->exchangeDeclare('logs', 'fanout'); $queue = $channel->queueDeclare('', false, false, true, false); -$channel->queueBind($queue->queue, 'logs'); +$channel->queueBind('logs', $queue->queue);
Non-Breaking Changes:
Client
andChannel
final
through doc block and introduced interfaces for them for unit testingreact/event-loop
,react/socket
, andreact/stream
for thatBreaking changes:
react/promise
v2 with v3-use Bunny\Async\Client; +use Bunny\Client; -use React\EventLoop\Factory;
require dirname(DIR, 2) . '/vendor/autoload.php';
-$loop = Factory::create();
-(new Client($loop))->connect(); +$client = new Client();
-$loop->run();
send.php
:Async
receive-async.php
:send-async.php
:string $queue
andstring $exchange
switched argument locationsuse Bunny\Channel; use Bunny\Client; use Bunny\Message;
require dirname(DIR, 2) . '/vendor/autoload.php';
$client = new Client(); $channel = $client->channel();
$channel->exchangeDeclare('logs', 'fanout'); $queue = $channel->queueDeclare('', false, false, true, false); -$channel->queueBind($queue->queue, 'logs'); +$channel->queueBind('logs', $queue->queue);