This commit is contained in:
as2252258@163.com
2021-03-23 02:38:20 +08:00
parent b9e2704313
commit e8b0f8da81
3 changed files with 838 additions and 814 deletions
+21
View File
@@ -18,6 +18,8 @@ use HttpServer\Service\Packet;
use HttpServer\Service\Websocket;
use Exception;
use ReflectionException;
use Rpc\Producer;
use Rpc\Service;
use Snowflake\Abstracts\Config;
use Snowflake\Core\Json;
use Snowflake\Error\LoggerProcess;
@@ -351,6 +353,25 @@ class Server extends HttpService
}
$this->onListenerBind($config, $this->baseServer);
return $this->startRpcService();
}
/**
* @return Http|Packet|Receive|Websocket|null
* @throws ComponentException
* @throws ConfigException
* @throws NotFindClassException
* @throws ReflectionException
*/
private function startRpcService()
{
$rpcService = Config::get('rpc.service', false, []);
if (is_array($rpcService) && !empty($rpcService)) {
/** @var Service $service */
$service = Snowflake::app()->get('rpc-service');
$service->instance($this->baseServer);
}
return $this->baseServer;
}
+5 -4
View File
@@ -3,9 +3,12 @@
namespace Rpc;
use HttpServer\Service\Http;
use HttpServer\Service\Packet;
use HttpServer\Service\Receive;
use HttpServer\Service\Websocket;
use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config;
use Snowflake\Snowflake;
/**
@@ -19,14 +22,12 @@ class Service extends Component
/**
* @throws \Snowflake\Exception\ConfigException
*/
public function instance(): void
public function instance(Packet|Websocket|Receive|null|Http $server): void
{
$services = Config::get('rpc.service', false, []);
if (empty($services)) {
return;
}
$server = Snowflake::app()->getSwoole();
foreach ($services as $service) {
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
+2
View File
@@ -447,6 +447,8 @@ abstract class BaseApplication extends Service
'crontab' => ['class' => Crontab::class],
'object' => ['class' => ObjectPool::class],
'goto' => ['class' => BaseGoto::class],
'rpc' => ['class' => \Rpc\Producer::class],
'rpc-service' => ['class' => \Rpc\Service::class],
'http2' => ['class' => Http2::class],
]);
}