Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9001dd041e | |||
| 1bb26b4680 | |||
| a6d825ef9b | |||
| 6cc0334b9b | |||
| d6cb6e40a8 | |||
| fb10622960 | |||
| 2a9c36babb | |||
| bc4e506ea8 | |||
| 59089462e7 | |||
| 845b8b36d1 | |||
| 07436f7035 | |||
| 4d93fcaff2 | |||
| 2e01b60e1e | |||
| 8d2ce1d45c | |||
| 8a3ed5aea5 | |||
| d50b6e6ec7 |
@@ -110,6 +110,7 @@ abstract class JsonRpcConsumers implements OnRpcConsumerInterface
|
||||
* @param $service
|
||||
* @return array
|
||||
* @throws RpcServiceException|\ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function get_consul($service): array
|
||||
{
|
||||
|
||||
+7
-10
@@ -7,14 +7,15 @@ use Http\Handler\Handler;
|
||||
use Http\Handler\Router;
|
||||
use Http\Message\ServerRequest;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Consul\Agent;
|
||||
use Kiri\Context;
|
||||
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;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use ReflectionException;
|
||||
@@ -46,13 +47,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
public Note $annotation;
|
||||
|
||||
|
||||
#[Inject(EventProvider::class)]
|
||||
public EventProvider $eventProvider;
|
||||
|
||||
|
||||
#[Inject(ContainerInterface::class)]
|
||||
public ContainerInterface $container;
|
||||
|
||||
|
||||
private RpcManager $manager;
|
||||
|
||||
@@ -67,7 +61,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
scan_directory(APP_PATH . 'rpc', 'Rpc');
|
||||
|
||||
$this->eventProvider->on(OnWorkerStart::class, [$this, 'consulWatches']);
|
||||
$this->eventProvider->on(OnTaskerStart::class, [$this, 'consulWatches']);
|
||||
$this->eventProvider->on(OnServerBeforeStart::class, [$this, 'register']);
|
||||
|
||||
$this->manager = Kiri::getDi()->get(RpcManager::class);
|
||||
@@ -76,8 +69,10 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
|
||||
/**
|
||||
* @param OnBeforeShutdown $beforeShutdown
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function onBeforeShutdown(OnBeforeShutdown $beforeShutdown)
|
||||
{
|
||||
@@ -92,13 +87,15 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
|
||||
/**
|
||||
* @param OnWorkerStart|OnTaskerStart $server
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function consulWatches(OnWorkerStart|OnTaskerStart $server)
|
||||
{
|
||||
if ($server->workerId != 0) {
|
||||
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') {
|
||||
Timer::clear($timeId);
|
||||
return;
|
||||
|
||||
+6
-3
@@ -3,12 +3,13 @@
|
||||
namespace Kiri\Rpc;
|
||||
|
||||
use Http\Handler\Handler;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Consul\Agent;
|
||||
use Kiri\Consul\Health;
|
||||
use Kiri\Kiri;
|
||||
use ReflectionException;
|
||||
|
||||
class RpcManager
|
||||
class RpcManager extends Component
|
||||
{
|
||||
|
||||
|
||||
@@ -87,8 +88,10 @@ class RpcManager
|
||||
}
|
||||
|
||||
foreach ($lists as $reflection) {
|
||||
if ($reflection->getDeclaringClass() != $class) {
|
||||
continue;
|
||||
}
|
||||
$methodName = $reflection->getName();
|
||||
|
||||
$this->_rpc[$name]['methods'][$methodName] = [new Handler('/', [$class, $methodName]), null];
|
||||
}
|
||||
return true;
|
||||
@@ -117,7 +120,7 @@ class RpcManager
|
||||
foreach ($this->_rpc as $list) {
|
||||
$data = $agent->service->register($list['config']);
|
||||
if ($data->getStatusCode() != 200) {
|
||||
exit($data->getBody());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user