-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild into async only with sync API
- Loading branch information
1 parent
464507a
commit 709ae09
Showing
143 changed files
with
3,573 additions
and
6,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
Breaking changes: | ||
* Raised minimum PHP version to 8.1+ | ||
* Dropped Event Loop injection and replaced it with the global loop accessor | ||
|
||
* Merged `Async` and `Sync` clients into `Client` utilizing fibers | ||
|
||
### 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`: | ||
```diff | ||
<?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(); | ||
``` | ||
|
||
### Async | ||
|
||
`receive_async.php`: | ||
```diff | ||
<?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()->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 | ||
- ); | ||
-}); | ||
|
||
+$client = new Client(); | ||
+$channel = $client->channel(); | ||
|
||
+$channel->queueDeclare('hello', false, false, false, false); | ||
|
||
+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.php`: | ||
```diff | ||
<?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(); | ||
``` | ||
|
||
* Channel::queueBind arguments `string $queue` and `string $exchange` switched argument locations | ||
```diff | ||
<?php | ||
|
||
use 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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
<?php | ||
namespace Bunny; | ||
|
||
use Bunny\Message; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
$c = new Client(); | ||
$ch = $c->connect()->channel(); | ||
|
||
$ch->queueDeclare("bench_queue"); | ||
$ch->exchangeDeclare("bench_exchange"); | ||
$ch->queueBind("bench_queue", "bench_exchange"); | ||
$ch->queueBind("bench_exchange", "bench_queue"); | ||
|
||
$t = null; | ||
$count = 0; | ||
|
||
$ch->run(function (Message $msg, Channel $ch, Client $c) use (&$t, &$count) { | ||
$ch->consume(function (Message $msg, Channel $ch, Client $c) use (&$t, &$count) { | ||
if ($t === null) { | ||
$t = microtime(true); | ||
} | ||
|
||
if ($msg->content === "quit") { | ||
printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t); | ||
$c->stop(); | ||
$c->disconnect(); | ||
} else { | ||
++$count; | ||
} | ||
|
||
}, "bench_queue", "", false, true); | ||
|
||
$c->disconnect(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.