11 Commits

Author SHA1 Message Date
as2252258 b0ed7650c5 Revert "改名"
This reverts commit fdf58326
2022-01-08 18:49:07 +08:00
as2252258 3d89cbd4c6 Revert "改名"
This reverts commit fdf58326
2022-01-05 15:22:29 +08:00
as2252258 0f2d19f3c7 Revert "改名"
This reverts commit fdf58326
2022-01-05 15:21:48 +08:00
as2252258 9001dd041e Revert "改名"
This reverts commit fdf58326
2022-01-04 15:56:37 +08:00
as2252258 1bb26b4680 改名 2021-12-24 14:53:59 +08:00
as2252258 a6d825ef9b 改名 2021-12-24 14:16:07 +08:00
as2252258 6cc0334b9b 改名 2021-12-24 11:55:09 +08:00
as2252258 d6cb6e40a8 改名 2021-12-24 11:53:24 +08:00
as2252258 fb10622960 改名 2021-12-24 11:34:29 +08:00
as2252258 2a9c36babb 改名 2021-12-24 11:31:48 +08:00
as2252258 bc4e506ea8 改名 2021-12-23 18:22:26 +08:00
16 changed files with 19 additions and 17 deletions
@@ -1,13 +1,13 @@
<?php
namespace Kiri\Rpc\Note;
namespace Kiri\Rpc\Annotation;
use Kiri\Abstracts\Config;
use Kiri\Core\Network;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Kiri\Rpc\RpcManager;
use Note\Attribute;
use Kiri\Annotation\Attribute;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends Attribute
@@ -23,10 +23,11 @@ use ReflectionException;
* @param array $tags
* @param array $meta
* @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
{
$rpcPort = Config::get('rpc.port');
if (empty($this->checkUrl)) {
$this->checkUrl = Network::local() . ":" . Config::get('rpc.port');
}
$defaultConfig = [
"ID" => "rpc.json.{$this->service}." . $this->uniqueId,
"Name" => $this->service,
@@ -66,9 +70,9 @@ use ReflectionException;
"Check" => [
"CheckId" => "service:rpc.json.{$this->service}." . $this->uniqueId,
"Name" => "service " . $this->service . ' health check',
"Notes" => "Script based health check",
"Annotations" => "Script based health check",
"ServiceID" => $this->service,
"TCP" => Network::local() . ":" . Config::get('rpc.port'),
"TCP" => $this->checkUrl,
"Interval" => "5s",
"Timeout" => "1s",
"DeregisterCriticalServiceAfter" => "30s"
@@ -110,6 +110,7 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface
* @param $service
* @return array
* @throws RpcServiceException|\ReflectionException
* @throws Exception
*/
private function get_consul($service): array
{
@@ -2,7 +2,7 @@
namespace Kiri\Rpc;
use Note\Inject;
use Kiri\Annotation\Inject;
use Exception;
use Http\Message\Response;
use Http\Message\Stream;
View File
+4 -6
View File
@@ -13,8 +13,8 @@ use Kiri\Context;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Note\Inject;
use Note\Note;
use Kiri\Annotation\Inject;
use Kiri\Annotation\Annotation;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ServerRequestInterface;
@@ -43,8 +43,8 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
public Router $router;
#[Inject(Note::class)]
public Note $annotation;
#[Inject(Annotation::class)]
public Annotation $annotation;
@@ -72,7 +72,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown)
{
@@ -107,7 +106,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
/**
* @param OnServerBeforeStart $server
* @throws ReflectionException
*/
public function register(OnServerBeforeStart $server)
{
+1 -2
View File
@@ -112,7 +112,6 @@ class RpcManager extends Component
/**
* @throws ReflectionException
*/
public function register()
{
@@ -120,7 +119,7 @@ class RpcManager extends Component
foreach ($this->_rpc as $list) {
$data = $agent->service->register($list['config']);
if ($data->getStatusCode() != 200) {
exit($data->getBody());
return;
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@
},
"autoload": {
"psr-4": {
"Kiri\\Rpc\\": "src/"
"Kiri\\Rpc\\": "./"
}
},
"require-dev": {
+1 -1
View File
@@ -61,7 +61,7 @@ return [
"node" => "t2.320",
"checkId" => "service:redis1",
"name" => "Redis health check",
"notes" => "Script based health check",
"Annotations" => "Script based health check",
"status" => "passing",
"serviceID" => "redis1",
"definition" => [