改名
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Rpc;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
|
||||
/**
|
||||
* Class Consumer
|
||||
* @package Annotation\Rpc
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Consumer extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Consumer constructor.
|
||||
* @param string $cmd
|
||||
*/
|
||||
public function __construct(public string $cmd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws ComponentException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): mixed
|
||||
{
|
||||
$rpc = Snowflake::app()->getRpc();
|
||||
$rpc->addConsumer($this->cmd, $handler);
|
||||
return parent::execute($handler); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Rpc;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
|
||||
/**
|
||||
* Class RpcClient
|
||||
* @package Annotation\Rpc
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)] class RpcService extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* RpcClient constructor.
|
||||
* @param string $cmd
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param int $mode
|
||||
*/
|
||||
public function __construct(
|
||||
public string $cmd,
|
||||
public string $host,
|
||||
public int $port,
|
||||
public int $mode = SWOOLE_SOCK_TCP6
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws ComponentException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): mixed
|
||||
{
|
||||
$rpc = Snowflake::app()->getRpc();
|
||||
$rpc->addProducer($this->cmd, $handler, [
|
||||
'host' => $this->host,
|
||||
'port' => $this->port,
|
||||
'mode' => $this->mode
|
||||
]);
|
||||
return parent::execute($handler); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user