变更
This commit is contained in:
+13
-10
@@ -4,6 +4,7 @@ namespace Kiri\Rpc;
|
||||
|
||||
use Exception;
|
||||
use Kiri;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Annotation\Inject;
|
||||
use Kiri\Consul\Agent;
|
||||
@@ -87,11 +88,9 @@ class RpcManager extends Component
|
||||
public function add(string $name, string $class, array $serviceConfig): bool
|
||||
{
|
||||
if (!isset($this->_rpc[$name])) {
|
||||
$this->_rpc[$name] = ['id' => $serviceConfig['ID'], 'config' => $serviceConfig];
|
||||
// $this->_rpc[$name] = ['id' => $serviceConfig['ID'], 'config' => $serviceConfig];
|
||||
}
|
||||
Router::addServer('rpc', static function () use ($name, $class) {
|
||||
|
||||
var_dump($name, $class);
|
||||
Router::get($name, $class);
|
||||
});
|
||||
return true;
|
||||
@@ -112,17 +111,21 @@ class RpcManager extends Component
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Kiri\Exception\ConfigException
|
||||
*/
|
||||
public function register()
|
||||
public function register(): void
|
||||
{
|
||||
$agent = Kiri::getDi()->get(Agent::class);
|
||||
foreach ($this->_rpc as $list) {
|
||||
$agent->service->deregister($list['config']['ID']);
|
||||
$data = $agent->service->register($list['config']);
|
||||
|
||||
$list = Config::get("rpc.consul", null, true);
|
||||
|
||||
$agent->service->deregister($list['ID']);
|
||||
$data = $agent->service->register($list);
|
||||
if ($data->getStatusCode() != 200) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->logger->error($data->getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user