This commit is contained in:
2021-12-02 16:13:57 +08:00
parent a66de3f016
commit 18d2ce66e6
4 changed files with 6 additions and 8 deletions
+1 -1
View File
@@ -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];
+1 -1
View File
@@ -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));
}
+2 -4
View File
@@ -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)) {
+2 -2
View File
@@ -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'];
}