Explode Response to Frames

This commit is contained in:
2021-01-30 17:14:19 +03:00
parent fc6b67cc92
commit f74b82a400
24 changed files with 367 additions and 148 deletions

View File

@ -4,6 +4,11 @@ declare(strict_types=1);
namespace Nsq;
use Nsq\Exception\NsqError;
use Nsq\Exception\NsqException;
use Nsq\Protocol\Error;
use Nsq\Protocol\Message;
final class Consumer extends Connection
{
private int $rdy = 0;
@ -13,7 +18,26 @@ final class Consumer extends Connection
*/
public function sub(string $topic, string $channel): void
{
$this->command('SUB', [$topic, $channel])->response()->okOrFail();
$this->command('SUB', [$topic, $channel])->checkIsOK();
}
public function readMessage(): ?Message
{
$frame = $this->readFrame();
if ($frame instanceof Message || null === $frame) {
return $frame;
}
if ($frame instanceof Error) {
if ($frame->type->terminateConnection) {
$this->disconnect();
}
throw new NsqError($frame);
}
throw new NsqException('Unreachable statement.');
}
/**