This commit is contained in:
2021-02-01 00:39:07 +03:00
parent 070b980003
commit 3d8f5be2d0
6 changed files with 261 additions and 14 deletions

View File

@@ -16,7 +16,9 @@ use Nsq\Protocol\Error;
use Nsq\Protocol\Frame;
use Nsq\Protocol\Message;
use Nsq\Protocol\Response;
use Nsq\Socket\DeflateSocket;
use Nsq\Socket\RawSocket;
use Nsq\Socket\SnappySocket;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
@@ -61,7 +63,24 @@ abstract class Connection
->toArray()
);
if ($this->connectionConfig->snappy || $this->connectionConfig->deflate) {
if ($this->connectionConfig->snappy) {
$this->socket = new NsqSocket(
new SnappySocket(
$socket,
$this->logger,
),
);
$this->checkIsOK();
}
if ($this->connectionConfig->deflate) {
$this->socket = new NsqSocket(
new DeflateSocket(
$socket,
),
);
$this->checkIsOK();
}
@@ -116,6 +135,8 @@ abstract class Connection
? $command
: implode(' ', [$command, ...((array) $params)]);
$this->logger->info('Command [{command}] with data [{data}]', ['command' => $command, 'data' => $data ?? 'null']);
$this->socket->write($command, $data);
return $this;
@@ -173,6 +194,8 @@ abstract class Connection
if (!$response->isOk()) {
throw new BadResponse($response);
}
$this->logger->info('Ok checked.');
}
private function readResponse(): Response