改名
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ class Protocol
|
|||||||
* @param string $data
|
* @param string $data
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public static function parse(string $data)
|
public static function parse(string $data): ?array
|
||||||
{
|
{
|
||||||
if (!str_contains($data, Protocol::SPLIT_STRING)) {
|
if (!str_contains($data, Protocol::SPLIT_STRING)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Kiri\Rpc;
|
namespace Kiri\Rpc;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Kiri\Exception\NotFindClassException;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
class Registry
|
class Registry
|
||||||
{
|
{
|
||||||
// KV
|
// KV
|
||||||
@@ -48,4 +52,17 @@ class Registry
|
|||||||
const DEFAULT_HTTP_TIMEOUT = 30;
|
const DEFAULT_HTTP_TIMEOUT = 30;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @return array
|
||||||
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getService($name): array
|
||||||
|
{
|
||||||
|
return di(Client::class)->get($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use Swoole\Server;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest
|
class RpcProvider extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -33,14 +33,14 @@ class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest
|
|||||||
{
|
{
|
||||||
$config['settings']['enable_delay_receive'] = true;
|
$config['settings']['enable_delay_receive'] = true;
|
||||||
$config['settings']['enable_unsafe_event'] = true;
|
$config['settings']['enable_unsafe_event'] = true;
|
||||||
$config['events'][Constant::RECEIVE] = [Service::class, 'onReceive'];
|
$config['events'][Constant::RECEIVE] = [RpcProvider::class, 'onReceive'];
|
||||||
$implements = class_implements(Service::class);
|
$implements = class_implements(RpcProvider::class);
|
||||||
if (in_array(OnConnect::class, $implements)) {
|
if (in_array(OnConnect::class, $implements)) {
|
||||||
$config['events'][Constant::CONNECT] = [Service::class, 'onConnect'];
|
$config['events'][Constant::CONNECT] = [RpcProvider::class, 'onConnect'];
|
||||||
}
|
}
|
||||||
if (in_array(OnClose::class, $implements)) {
|
if (in_array(OnClose::class, $implements)) {
|
||||||
$config['events'][Constant::DISCONNECT] = [Service::class, 'onDisconnect'];
|
$config['events'][Constant::DISCONNECT] = [RpcProvider::class, 'onDisconnect'];
|
||||||
$config['events'][Constant::CLOSE] = [Service::class, 'onClose'];
|
$config['events'][Constant::CLOSE] = [RpcProvider::class, 'onClose'];
|
||||||
}
|
}
|
||||||
$manager->addListener(
|
$manager->addListener(
|
||||||
$config['type'], $config['host'], $config['port'], $config['mode'], $config
|
$config['type'], $config['host'], $config['port'], $config['mode'], $config
|
||||||
@@ -87,16 +87,14 @@ class Service extends Tcp implements OnClose, OnConnect, OnReceive, OnRequest
|
|||||||
public function onReceive(Server $server, int $fd, int $reactor_id, string $data): void
|
public function onReceive(Server $server, int $fd, int $reactor_id, string $data): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// TODO: Implement onReceive() method.
|
|
||||||
[$cmd, [$body, $protocol]] = Protocol::parse($data);
|
[$cmd, [$body, $protocol]] = Protocol::parse($data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch(\Throwable $throwable){
|
} catch(\Throwable $throwable){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user