diff --git a/RpcJsonp.php b/RpcJsonp.php index d4f3dfb..b8c372f 100644 --- a/RpcJsonp.php +++ b/RpcJsonp.php @@ -94,7 +94,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa return; } $async_time = (int)Config::get('consul.async_time', 1000); - Timer::tick(5000, static function ($timeId) { + Timer::tick($async_time, static function ($timeId) { if (env('state', 'start') == 'exit') { Timer::clear($timeId); return; diff --git a/RpcManager.php b/RpcManager.php index 029d8d2..ccbc201 100644 --- a/RpcManager.php +++ b/RpcManager.php @@ -2,10 +2,11 @@ namespace Kiri\Rpc; +use Exception; +use Kiri; use Kiri\Abstracts\Component; use Kiri\Consul\Agent; use Kiri\Consul\Health; -use Kiri; use Kiri\Message\Handler\Handler; use ReflectionException; @@ -22,11 +23,12 @@ class RpcManager extends Component /** * @param $serviceName * @return void - * @throws ReflectionException - * @throws \Exception + * @throws Exception */ public function async($serviceName): void { + $this->reRegister($serviceName); + $lists = Kiri::getDi()->get(Health::class)->setQuery('passing=true')->service($serviceName); if ($lists->getStatusCode() != 200) { return; @@ -41,8 +43,33 @@ class RpcManager extends Component } + /** + * @param string $serviceName + * @return void + * @throws Kiri\Exception\ConfigException + * @throws Exception + */ + public function reRegister(string $serviceName) + { + $config = $this->_rpc[$serviceName] ?? []; + if (empty($config)) { + return; + } + $service = Kiri::getDi()->get(Agent::class); + + $info = $service->service->service_health($config['config']['ID']); + if ($info->getStatusCode() == 200) { + return; + } + $data = $service->service->register($config['config']); + + $this->logger()->info($data); + } + + /** * @throws ReflectionException + * @throws Exception */ public function tick(): void { @@ -55,7 +82,7 @@ class RpcManager extends Component /** * @param $serviceName * @return array - * @throws \Exception + * @throws Exception */ public function getServices($serviceName): array {