diff --git a/src/ClientPool.php b/src/ClientPool.php index 3cd62eb..1d1c4d7 100644 --- a/src/ClientPool.php +++ b/src/ClientPool.php @@ -41,7 +41,7 @@ class ClientPool extends Component */ public function get($config, callable $callback): mixed { - $coroutineName = $this->name(self::POOL_NAME . '::' . $config['ServiceAddress'] . '::' . $config['ServicePort'], true); + $coroutineName = $this->name(self::POOL_NAME . '::' . $config['Address'] . '::' . $config['Port'], true); $pool = $config['pool'] ?? ['min' => 1, 'max' => 100]; diff --git a/src/JsonRpcPoolTransporter.php b/src/JsonRpcPoolTransporter.php index a5bb5d4..0f3e87f 100644 --- a/src/JsonRpcPoolTransporter.php +++ b/src/JsonRpcPoolTransporter.php @@ -45,7 +45,7 @@ class JsonRpcPoolTransporter implements ClientInterface $response = $this->request($client = $this->getClient(), $content, false); - $this->pool->push($client, $this->config['ServiceAddress'], $this->config['ServicePort']); + $this->pool->push($client, $this->config['Address'], $this->config['Port']); return (new Response())->withBody(new Stream($response)); } diff --git a/src/RpcManager.php b/src/RpcManager.php index 4ad5b77..0d752d6 100644 --- a/src/RpcManager.php +++ b/src/RpcManager.php @@ -2,12 +2,10 @@ namespace Kiri\Rpc; -use Kiri\Abstracts\Config; use Kiri\Consul\Agent; use Kiri\Consul\Health; use Kiri\Kiri; use ReflectionException; -use Swoole\Table; class RpcManager { @@ -60,8 +58,8 @@ class RpcManager public function getServices($serviceName): array { $file = storage('.rpc.clients.' . md5($serviceName), 'rpc'); - if (!file_exists($file)) { - $this->tick(); + if (!file_exists($file) || filesize($file) < 10) { + $this->async($serviceName); } $content = json_decode(file_get_contents($file), true); if (empty($content) || !is_array($content)) { diff --git a/src/TraitTransporter.php b/src/TraitTransporter.php index da38dd3..13ac131 100644 --- a/src/TraitTransporter.php +++ b/src/TraitTransporter.php @@ -57,7 +57,7 @@ trait TraitTransporter $client = Context::inCoroutine() ? new Coroutine\Client(SWOOLE_SOCK_TCP) : new Client(SWOOLE_SOCK_TCP); $this->clients[$alias] = $client; } - [$host, $port] = [$this->config['ServiceAddress'], $this->config['ServicePort']]; + [$host, $port] = [$this->config['Address'], $this->config['Port']]; if (!$client->isConnected() && !$client->connect($host, $port, 60)) { throw new Exception('connect fail.'); } @@ -71,7 +71,7 @@ trait TraitTransporter */ private function alias(array $config): string { - return $config['ServiceAddress'] . '::' . $config['ServicePort']; + return $config['Address'] . '::' . $config['Port']; }