改名
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kiri\Rpc\Note;
|
||||
|
||||
use Kiri\Consul\Catalog\Catalog;
|
||||
use Note\Attribute;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Consul\Agent;
|
||||
@@ -40,8 +41,8 @@ use ReflectionException;
|
||||
public function execute(mixed $class, mixed $method = ''): bool
|
||||
{
|
||||
$default = $this->create();
|
||||
$agent = Kiri::getDi()->get(Agent::class);
|
||||
$data = $agent->service->register($default);
|
||||
$agent = Kiri::getDi()->get(Catalog::class);
|
||||
$data = $agent->register($default);
|
||||
if ($data->getStatusCode() != 200) {
|
||||
exit($data->getBody()->getContents());
|
||||
}
|
||||
|
||||
+17
-6
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace Kiri\Rpc;
|
||||
|
||||
use Note\Note;
|
||||
use Note\Inject;
|
||||
use Http\Constrict\RequestInterface;
|
||||
use Http\Handler\Router;
|
||||
use Http\Message\ServerRequest;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Consul\Agent;
|
||||
use Kiri\Consul\Catalog\Catalog;
|
||||
use Kiri\Context;
|
||||
use Kiri\Core\Json;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Note\Inject;
|
||||
use Note\Note;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -23,7 +23,7 @@ use Server\Contract\OnCloseInterface;
|
||||
use Server\Contract\OnConnectInterface;
|
||||
use Server\Contract\OnReceiveInterface;
|
||||
use Server\Events\OnBeforeShutdown;
|
||||
use Server\Events\OnStart;
|
||||
use Server\Events\OnWorkerStart;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine\Channel;
|
||||
use Swoole\Server;
|
||||
@@ -60,6 +60,8 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
$this->eventProvider->on(OnBeforeShutdown::class, [$this, 'onBeforeShutdown']);
|
||||
|
||||
scan_directory(APP_PATH . 'rpc', 'Rpc');
|
||||
|
||||
$this->eventProvider->on(OnWorkerStart::class, [$this, 'register']);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,15 +81,24 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
|
||||
|
||||
/**
|
||||
* @param OnStart $server
|
||||
* @param OnWorkerStart $server
|
||||
* @throws ConfigException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function register(OnStart $server)
|
||||
public function register(OnWorkerStart $server)
|
||||
{
|
||||
if ($server->workerId != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = Config::get('rpc');
|
||||
|
||||
$catalog = $this->container->get(Catalog::class);
|
||||
$catalog->register([
|
||||
|
||||
]);
|
||||
|
||||
$agent = $this->container->get(Agent::class);
|
||||
$data = $agent->service->register($config['registry']['config']);
|
||||
if ($data->getStatusCode() != 200) {
|
||||
|
||||
@@ -29,5 +29,49 @@ return [
|
||||
'port' => ''
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
|
||||
'service' => [
|
||||
[
|
||||
"datacenter" => "dc1",
|
||||
"id" => "40e4a748-2192-161a-0510-9bf59fe950b5",
|
||||
"node" => "FriendRpcService",
|
||||
"skipNodeUpdate" => false,
|
||||
"service" => [
|
||||
"id" => "redis1",
|
||||
"service" => "FriendRpcService",
|
||||
"address" => "172.26.221.211",
|
||||
"taggedAddresses" => [
|
||||
"lan" => [
|
||||
"address" => "127.0.0.1",
|
||||
"port" => 8000
|
||||
],
|
||||
"wan" => [
|
||||
"address" => "172.26.221.211",
|
||||
"port" => 80
|
||||
]
|
||||
],
|
||||
"meta" => [
|
||||
"redis_version" => "4.0"
|
||||
],
|
||||
"port" => 8000
|
||||
],
|
||||
"check" => [
|
||||
"node" => "t2.320",
|
||||
"checkId" => "service:redis1",
|
||||
"name" => "Redis health check",
|
||||
"notes" => "Script based health check",
|
||||
"status" => "passing",
|
||||
"serviceID" => "redis1",
|
||||
"definition" => [
|
||||
"http" => "172.26.221.211:9527",
|
||||
"interval" => "5s",
|
||||
"timeout" => "1s",
|
||||
"deregisterCriticalServiceAfter" => "30s"
|
||||
],
|
||||
],
|
||||
]
|
||||
|
||||
]
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user