-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from mermshaus/issue-125
Add test to illustrate #125 (stream_select/interrupt issue). Also a fix
- Loading branch information
Showing
10 changed files
with
179 additions
and
70 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
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bunny\Test\Library; | ||
|
||
final class Paths | ||
{ | ||
public static function getTestsRootPath(): string | ||
{ | ||
return dirname(__DIR__); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bunny\Test\Library; | ||
|
||
function parseAmqpUri($uri): array | ||
{ | ||
$uriComponents = parse_url($uri); | ||
|
||
if ( | ||
!isset($uriComponents['scheme']) | ||
|| !in_array($uriComponents['scheme'], ['amqp', 'amqps']) | ||
) { | ||
throw new \RuntimeException( | ||
sprintf( | ||
'URI scheme must be "amqp" or "amqps". URI given: "%s"', | ||
$uri | ||
) | ||
); | ||
} | ||
|
||
$options = []; | ||
|
||
if (isset($uriComponents['host'])) { | ||
$options['host'] = $uriComponents['host']; | ||
} | ||
|
||
if (isset($uriComponents['port'])) { | ||
$options['port'] = $uriComponents['port']; | ||
} | ||
|
||
if (isset($uriComponents['user'])) { | ||
$options['user'] = $uriComponents['user']; | ||
} | ||
|
||
if (isset($uriComponents['pass'])) { | ||
$options['password'] = $uriComponents['pass']; | ||
} | ||
|
||
if (isset($uriComponents['path'])) { | ||
$vhostCandidate = $uriComponents['path']; | ||
|
||
if (strpos($vhostCandidate, '/') === 0) { | ||
$vhostCandidate = substr($vhostCandidate, 1); | ||
} | ||
|
||
if (strpos($vhostCandidate, '/') !== false) { | ||
throw new \RuntimeException( | ||
sprintf( | ||
'An URI path component that is a valid vhost may not contain unescaped "/" characters. URI given: "%s"', | ||
$uri | ||
) | ||
); | ||
} | ||
|
||
$vhostCandidate = rawurldecode($vhostCandidate); | ||
|
||
$options['vhost'] = $vhostCandidate; | ||
} | ||
|
||
if ($options['vhost'] === '') { | ||
$options['vhost'] = '/'; | ||
} | ||
|
||
return $options; | ||
} |
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,51 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
// Usage: bunny-consumer.php <amqp-uri> <queue-name> <max-seconds> | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bunny\Test\App; | ||
|
||
use Bunny\Channel; | ||
use Bunny\Client; | ||
use Bunny\Message; | ||
|
||
use function Bunny\Test\Library\parseAmqpUri; | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
function app(array $args) | ||
{ | ||
$connection = parseAmqpUri($args['amqpUri']); | ||
|
||
$client = new Client($connection); | ||
|
||
pcntl_signal(SIGINT, function () use ($client) { | ||
$client->disconnect()->done(function () use ($client) { | ||
$client->stop(); | ||
}); | ||
}); | ||
|
||
$client->connect(); | ||
$channel = $client->channel(); | ||
|
||
$channel->qos(0, 1); | ||
$channel->queueDeclare($args['queueName']); | ||
$channel->consume(function (Message $message, Channel $channel) use ($client) { | ||
$channel->ack($message); | ||
}); | ||
$client->run($args['maxSeconds'] > 0 ? $args['maxSeconds'] : null); | ||
} | ||
|
||
$argv_copy = $argv; | ||
|
||
array_shift($argv_copy); | ||
|
||
$args = [ | ||
'amqpUri' => array_shift($argv_copy), | ||
'queueName' => array_shift($argv_copy), | ||
'maxSeconds' => (int) array_shift($argv_copy), | ||
]; | ||
|
||
app($args); |