This commit is contained in:
xl
2023-05-20 23:05:38 +08:00
parent de2698ee12
commit d72ff2f82c
7 changed files with 183 additions and 163 deletions
+12 -20
View File
@@ -2,15 +2,9 @@
namespace Kiri\Rpc;
use Kiri\Annotation\Inject;
use Exception;
use Kiri\Message\Response;
use Kiri\Message\Stream;
use Kiri\Abstracts\Config;
use Kiri\Di\Inject\Container;
use Kiri\Exception\ConfigException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Swoole\Coroutine\Client;
class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
{
@@ -19,16 +13,18 @@ class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
use TraitTransporter;
#[Inject(ClientPool::class)]
#[Container(ClientPool::class)]
public ClientPool $pool;
/**
* @param string $content
* @param string $service
* @return string|bool
* @throws ConfigException|RpcServiceException
*/
/**
* @param string $content
* @param string $service
* @return string|bool
* @throws ConfigException
* @throws RpcServiceException
* @throws \ReflectionException
*/
public function push(string $content, string $service): string|bool
{
$client = $this->get_consul($service)->getClient();
@@ -42,16 +38,12 @@ class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
/**
* @return Client|\Swoole\Client
* @throws ConfigException
* @throws Exception
*/
private function getClient(): Client|\Swoole\Client
private function getClient()
{
$this->config['pool'] = Config::get('rpc.pool', ['max' => 10, 'min' => 1, 'waite' => 60]);
return $this->pool->get($this->config, function () {
return $this->newClient();
});
return $this->pool->get($this->config);
}