modify
This commit is contained in:
@@ -18,6 +18,8 @@ use HttpServer\Service\Packet;
|
|||||||
use HttpServer\Service\Websocket;
|
use HttpServer\Service\Websocket;
|
||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use Rpc\Producer;
|
||||||
|
use Rpc\Service;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
use Snowflake\Core\Json;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Error\LoggerProcess;
|
use Snowflake\Error\LoggerProcess;
|
||||||
@@ -351,6 +353,25 @@ class Server extends HttpService
|
|||||||
}
|
}
|
||||||
$this->onListenerBind($config, $this->baseServer);
|
$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;
|
return $this->baseServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -3,9 +3,12 @@
|
|||||||
namespace Rpc;
|
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\Component;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
use Snowflake\Snowflake;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,14 +22,12 @@ class Service extends Component
|
|||||||
/**
|
/**
|
||||||
* @throws \Snowflake\Exception\ConfigException
|
* @throws \Snowflake\Exception\ConfigException
|
||||||
*/
|
*/
|
||||||
public function instance(): void
|
public function instance(Packet|Websocket|Receive|null|Http $server): void
|
||||||
{
|
{
|
||||||
$services = Config::get('rpc.service', false, []);
|
$services = Config::get('rpc.service', false, []);
|
||||||
if (empty($services)) {
|
if (empty($services)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$server = Snowflake::app()->getSwoole();
|
|
||||||
foreach ($services as $service) {
|
foreach ($services as $service) {
|
||||||
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
|
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
|
||||||
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
|
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
|
||||||
|
|||||||
@@ -447,6 +447,8 @@ abstract class BaseApplication extends Service
|
|||||||
'crontab' => ['class' => Crontab::class],
|
'crontab' => ['class' => Crontab::class],
|
||||||
'object' => ['class' => ObjectPool::class],
|
'object' => ['class' => ObjectPool::class],
|
||||||
'goto' => ['class' => BaseGoto::class],
|
'goto' => ['class' => BaseGoto::class],
|
||||||
|
'rpc' => ['class' => \Rpc\Producer::class],
|
||||||
|
'rpc-service' => ['class' => \Rpc\Service::class],
|
||||||
'http2' => ['class' => Http2::class],
|
'http2' => ['class' => Http2::class],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user