Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da056b09c7 | |||
| 4eefe54be0 | |||
| b0ed7650c5 | |||
| 3d89cbd4c6 | |||
| 0f2d19f3c7 |
@@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Kiri\Rpc\Note;
|
namespace Kiri\Rpc\Annotation;
|
||||||
|
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Core\Network;
|
use Kiri\Core\Network;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Kiri\Rpc\RpcManager;
|
use Kiri\Rpc\RpcManager;
|
||||||
use Note\Attribute;
|
use Kiri\Annotation\Attribute;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends Attribute
|
#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends Attribute
|
||||||
@@ -23,10 +23,11 @@ use ReflectionException;
|
|||||||
* @param array $tags
|
* @param array $tags
|
||||||
* @param array $meta
|
* @param array $meta
|
||||||
* @param array $checkOptions
|
* @param array $checkOptions
|
||||||
|
* @param string $checkUrl
|
||||||
*/
|
*/
|
||||||
public function __construct(public string $service, public string $driver, public array $tags = [], public array $meta = [], public array $checkOptions = [])
|
public function __construct(public string $service, public string $driver, public array $tags = [], public array $meta = [], public array $checkOptions = [], public string $checkUrl = '')
|
||||||
{
|
{
|
||||||
$this->uniqueId = preg_replace('/(\w{11})(\w{4})(\w{3})(\w{8})(\w{6})/', '$1-$2-$3-$4-$5', md5(__DIR__ . '.' . md5(Network::local())));
|
$this->uniqueId = preg_replace('/(\w{11})(\w{4})(\w{3})(\w{8})(\w{6})/', '$1-$2-$3-$4-$5', md5(__DIR__ . 'Annotation' . md5(Network::local())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -49,6 +50,9 @@ use ReflectionException;
|
|||||||
protected function create(): array
|
protected function create(): array
|
||||||
{
|
{
|
||||||
$rpcPort = Config::get('rpc.port');
|
$rpcPort = Config::get('rpc.port');
|
||||||
|
if (empty($this->checkUrl)) {
|
||||||
|
$this->checkUrl = Network::local() . ":" . Config::get('rpc.port');
|
||||||
|
}
|
||||||
$defaultConfig = [
|
$defaultConfig = [
|
||||||
"ID" => "rpc.json.{$this->service}." . $this->uniqueId,
|
"ID" => "rpc.json.{$this->service}." . $this->uniqueId,
|
||||||
"Name" => $this->service,
|
"Name" => $this->service,
|
||||||
@@ -66,9 +70,9 @@ use ReflectionException;
|
|||||||
"Check" => [
|
"Check" => [
|
||||||
"CheckId" => "service:rpc.json.{$this->service}." . $this->uniqueId,
|
"CheckId" => "service:rpc.json.{$this->service}." . $this->uniqueId,
|
||||||
"Name" => "service " . $this->service . ' health check',
|
"Name" => "service " . $this->service . ' health check',
|
||||||
"Notes" => "Script based health check",
|
"Annotations" => "Script based health check",
|
||||||
"ServiceID" => $this->service,
|
"ServiceID" => $this->service,
|
||||||
"TCP" => Network::local() . ":" . Config::get('rpc.port'),
|
"TCP" => $this->checkUrl,
|
||||||
"Interval" => "5s",
|
"Interval" => "5s",
|
||||||
"Timeout" => "1s",
|
"Timeout" => "1s",
|
||||||
"DeregisterCriticalServiceAfter" => "30s"
|
"DeregisterCriticalServiceAfter" => "30s"
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Kiri\Rpc;
|
namespace Kiri\Rpc;
|
||||||
|
|
||||||
use Note\Inject;
|
use Kiri\Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Http\Message\Response;
|
use Http\Message\Response;
|
||||||
use Http\Message\Stream;
|
use Http\Message\Stream;
|
||||||
@@ -13,8 +13,8 @@ use Kiri\Context;
|
|||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Note\Inject;
|
use Kiri\Annotation\Inject;
|
||||||
use Note\Note;
|
use Kiri\Annotation\Annotation;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -43,8 +43,8 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
|||||||
public Router $router;
|
public Router $router;
|
||||||
|
|
||||||
|
|
||||||
#[Inject(Note::class)]
|
#[Inject(Annotation::class)]
|
||||||
public Note $annotation;
|
public Annotation $annotation;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +72,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown)
|
public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown)
|
||||||
{
|
{
|
||||||
@@ -107,7 +106,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OnServerBeforeStart $server
|
* @param OnServerBeforeStart $server
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function register(OnServerBeforeStart $server)
|
public function register(OnServerBeforeStart $server)
|
||||||
{
|
{
|
||||||
@@ -266,10 +264,9 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
|
||||||
* @param int $fd
|
* @param int $fd
|
||||||
*/
|
*/
|
||||||
public function onClose(Server $server, int $fd): void
|
public function onClose(int $fd): void
|
||||||
{
|
{
|
||||||
// TODO: Implement onClose() method.
|
// TODO: Implement onClose() method.
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,6 @@ class RpcManager extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Kiri\\Rpc\\": "src/"
|
"Kiri\\Rpc\\": "./"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ return [
|
|||||||
"node" => "t2.320",
|
"node" => "t2.320",
|
||||||
"checkId" => "service:redis1",
|
"checkId" => "service:redis1",
|
||||||
"name" => "Redis health check",
|
"name" => "Redis health check",
|
||||||
"notes" => "Script based health check",
|
"Annotations" => "Script based health check",
|
||||||
"status" => "passing",
|
"status" => "passing",
|
||||||
"serviceID" => "redis1",
|
"serviceID" => "redis1",
|
||||||
"definition" => [
|
"definition" => [
|
||||||
Reference in New Issue
Block a user