This commit is contained in:
as2252258@163.com
2021-05-03 03:48:52 +08:00
parent a90e647529
commit 8137b24865
25 changed files with 273 additions and 306 deletions
+28 -28
View File
@@ -16,39 +16,39 @@ use Snowflake\Snowflake;
#[\Attribute(\Attribute::TARGET_CLASS)] class RpcClient extends Attribute
{
private array $config;
private array $config;
/**
* RpcClient constructor.
* @param string $cmd
* @param int $port
* @param int $timeout
* @param int $mode
*/
public function __construct(
public string $cmd,
public int $port,
public int $timeout,
public int $mode
)
{
$this->config = ['port' => $port, 'mode' => $mode, 'timeout' => $timeout];
}
/**
* RpcClient constructor.
* @param string $cmd
* @param int $port
* @param int $timeout
* @param int $mode
*/
public function __construct(
public string $cmd,
public int $port,
public int $timeout,
public int $mode
)
{
$this->config = ['port' => $port, 'mode' => $mode, 'timeout' => $timeout];
}
/**
* @param array $handler
* @return mixed
* @throws Exception
*/
public function execute(array $handler): mixed
{
$rpc = Snowflake::app()->getRpc();
$rpc->addProducer($this->cmd, $handler, $this->config);
/**
* @param array $handler
* @return mixed
* @throws Exception
*/
public function execute(mixed $class, mixed $method = ''): mixed
{
$rpc = Snowflake::app()->getRpc();
$rpc->addProducer($this->cmd, [$class, $method], $this->config);
return parent::execute($handler);
}
return true;
}
}