Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 845b8b36d1 | |||
| 07436f7035 | |||
| 4d93fcaff2 | |||
| 2e01b60e1e | |||
| 8d2ce1d45c | |||
| 8a3ed5aea5 | |||
| d50b6e6ec7 |
+5
-7
@@ -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;
|
||||||
@@ -50,10 +51,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
|||||||
public EventProvider $eventProvider;
|
public EventProvider $eventProvider;
|
||||||
|
|
||||||
|
|
||||||
#[Inject(ContainerInterface::class)]
|
|
||||||
public ContainerInterface $container;
|
|
||||||
|
|
||||||
|
|
||||||
private RpcManager $manager;
|
private RpcManager $manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +64,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);
|
||||||
@@ -92,13 +88,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
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user