Files

50 lines
914 B
PHP
Raw Permalink Normal View History

2022-01-09 14:00:32 +08:00
<?php
namespace Kiri\Rpc;
use Exception;
2023-05-20 23:05:38 +08:00
use Kiri\Di\Inject\Container;
2022-01-09 14:00:32 +08:00
use Kiri\Exception\ConfigException;
2023-10-24 17:22:31 +08:00
use ReflectionException;
2022-01-09 14:00:32 +08:00
2022-09-23 18:55:46 +08:00
class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
2022-01-09 14:00:32 +08:00
{
use TraitTransporter;
2023-05-20 23:05:38 +08:00
#[Container(ClientPool::class)]
2022-01-09 14:00:32 +08:00
public ClientPool $pool;
2023-05-20 23:05:38 +08:00
/**
* @param string $content
* @param string $service
* @return string|bool
* @throws RpcServiceException
2023-10-24 17:22:31 +08:00
* @throws ReflectionException
2023-05-20 23:05:38 +08:00
*/
2022-09-23 18:55:46 +08:00
public function push(string $content, string $service): string|bool
2022-01-09 14:00:32 +08:00
{
2022-09-23 18:55:46 +08:00
$client = $this->get_consul($service)->getClient();
2022-06-08 15:08:07 +08:00
2022-06-08 17:19:32 +08:00
$response = $this->request($client, $content);
2022-01-09 14:00:32 +08:00
$this->pool->push($client, $this->config['Address'], $this->config['Port']);
2022-09-23 18:55:46 +08:00
return $response;
2022-01-09 14:00:32 +08:00
}
/**
2023-10-24 17:22:31 +08:00
* @throws Exception
2022-01-09 14:00:32 +08:00
*/
2023-05-20 23:05:38 +08:00
private function getClient()
2022-01-09 14:00:32 +08:00
{
2023-05-20 23:05:38 +08:00
return $this->pool->get($this->config);
2022-01-09 14:00:32 +08:00
}
}