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