15 Commits

Author SHA1 Message Date
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
as2252258 59089462e7 改名 2021-12-08 11:32:32 +08:00
as2252258 845b8b36d1 改名 2021-12-06 17:10:45 +08:00
as2252258 07436f7035 改名 2021-12-06 17:08:03 +08:00
as2252258 4d93fcaff2 改名 2021-12-03 15:42:05 +08:00
as2252258 2e01b60e1e 改名 2021-12-03 15:09:05 +08:00
as2252258 8d2ce1d45c 改名 2021-12-03 15:07:21 +08:00
as2252258 8a3ed5aea5 改名 2021-12-03 14:56:13 +08:00
as2252258 d50b6e6ec7 改名 2021-12-03 14:46:38 +08:00
3 changed files with 13 additions and 12 deletions
+1
View File
@@ -110,6 +110,7 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface
* @param $service * @param $service
* @return array * @return array
* @throws RpcServiceException|\ReflectionException * @throws RpcServiceException|\ReflectionException
* @throws Exception
*/ */
private function get_consul($service): array private function get_consul($service): array
{ {
+7 -10
View File
@@ -7,14 +7,15 @@ use Http\Handler\Handler;
use Http\Handler\Router; use Http\Handler\Router;
use Http\Message\ServerRequest; use Http\Message\ServerRequest;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Consul\Agent; use Kiri\Consul\Agent;
use Kiri\Context; use Kiri\Context;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Note\Inject; use Note\Inject;
use Note\Note; use Note\Note;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use ReflectionException; use ReflectionException;
@@ -46,13 +47,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
public Note $annotation; public Note $annotation;
#[Inject(EventProvider::class)]
public EventProvider $eventProvider;
#[Inject(ContainerInterface::class)]
public ContainerInterface $container;
private RpcManager $manager; private RpcManager $manager;
@@ -67,7 +61,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
scan_directory(APP_PATH . 'rpc', 'Rpc'); scan_directory(APP_PATH . 'rpc', 'Rpc');
$this->eventProvider->on(OnWorkerStart::class, [$this, 'consulWatches']); $this->eventProvider->on(OnWorkerStart::class, [$this, 'consulWatches']);
$this->eventProvider->on(OnTaskerStart::class, [$this, 'consulWatches']);
$this->eventProvider->on(OnServerBeforeStart::class, [$this, 'register']); $this->eventProvider->on(OnServerBeforeStart::class, [$this, 'register']);
$this->manager = Kiri::getDi()->get(RpcManager::class); $this->manager = Kiri::getDi()->get(RpcManager::class);
@@ -76,8 +69,10 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
/** /**
* @param OnBeforeShutdown $beforeShutdown * @param OnBeforeShutdown $beforeShutdown
* @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown) public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown)
{ {
@@ -92,13 +87,15 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
/** /**
* @param OnWorkerStart|OnTaskerStart $server * @param OnWorkerStart|OnTaskerStart $server
* @throws ConfigException
*/ */
public function consulWatches(OnWorkerStart|OnTaskerStart $server) public function consulWatches(OnWorkerStart|OnTaskerStart $server)
{ {
if ($server->workerId != 0) { if ($server->workerId != 0) {
return; return;
} }
Timer::tick(1000, static function ($timeId) { $async_time = (int)Config::get('consul.async_time', 1000);
Timer::tick($async_time, static function ($timeId) {
if (env('state', 'start') == 'exit') { if (env('state', 'start') == 'exit') {
Timer::clear($timeId); Timer::clear($timeId);
return; return;
+5 -2
View File
@@ -3,12 +3,13 @@
namespace Kiri\Rpc; namespace Kiri\Rpc;
use Http\Handler\Handler; use Http\Handler\Handler;
use Kiri\Abstracts\Component;
use Kiri\Consul\Agent; use Kiri\Consul\Agent;
use Kiri\Consul\Health; use Kiri\Consul\Health;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException; use ReflectionException;
class RpcManager class RpcManager extends Component
{ {
@@ -87,8 +88,10 @@ class RpcManager
} }
foreach ($lists as $reflection) { foreach ($lists as $reflection) {
if ($reflection->getDeclaringClass() != $class) {
continue;
}
$methodName = $reflection->getName(); $methodName = $reflection->getName();
$this->_rpc[$name]['methods'][$methodName] = [new Handler('/', [$class, $methodName]), null]; $this->_rpc[$name]['methods'][$methodName] = [new Handler('/', [$class, $methodName]), null];
} }
return true; return true;