From 9f95dff2ec07bf16336f14ab492be676e873e0d4 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Sat, 23 Jan 2021 02:16:29 +0300 Subject: [PATCH] Allow configure heartbeat_interval --- src/Connection.php | 15 +++++++++++---- tests/NsqTest.php | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index a663b94..43cec9d 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -22,16 +22,21 @@ use const PHP_EOL; */ abstract class Connection { - public ?Socket $socket = null; + private string $address; - protected LoggerInterface $logger; + private ?Socket $socket = null; private bool $closed = false; - private string $address; + private LoggerInterface $logger; /** - * @var array{client_id: string, hostname: string, user_agent: string} + * @var array{ + * client_id: string, + * hostname: string, + * user_agent: string, + * heartbeat_interval: int|null, + * } */ private array $features; @@ -41,6 +46,7 @@ abstract class Connection string $clientId = null, string $hostname = null, string $userAgent = null, + int $heartbeatInterval = null, ) { $this->address = $address; @@ -48,6 +54,7 @@ abstract class Connection 'client_id' => $clientId ?? '', 'hostname' => $hostname ?? (static fn (mixed $host): string => \is_string($host) ? $host : '')(gethostname()), 'user_agent' => $userAgent ?? 'nsqphp/'.InstalledVersions::getPrettyVersion('nsq/nsq'), + 'heartbeat_interval' => $heartbeatInterval, ]; $this->logger = $logger ?? new NullLogger(); diff --git a/tests/NsqTest.php b/tests/NsqTest.php index c6a39a8..8da7a50 100644 --- a/tests/NsqTest.php +++ b/tests/NsqTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -use Nsq\Message; use Nsq\Consumer; -use Nsq\Subscriber; -use Nsq\Producer; use Nsq\Exception; +use Nsq\Message; +use Nsq\Producer; +use Nsq\Subscriber; use PHPUnit\Framework\TestCase; final class NsqTest extends TestCase @@ -16,7 +16,14 @@ final class NsqTest extends TestCase $producer = new Producer('tcp://localhost:4150'); $producer->pub(__FUNCTION__, __FUNCTION__); - $consumer = new Consumer('tcp://localhost:4150'); + $consumer = new Consumer( + 'tcp://localhost:4150', + null, + null, + null, + null, + 1000, + ); $subscriber = new Subscriber($consumer); $generator = $subscriber->subscribe(__FUNCTION__, __FUNCTION__, 1);