This commit is contained in:
2021-03-23 16:14:05 +08:00
parent 98681a0dfa
commit 65332ec6b1
11 changed files with 946 additions and 820 deletions
+12 -6
View File
@@ -6,6 +6,7 @@ namespace Annotation\Rpc;
use Annotation\Attribute;
use ReflectionException;
use Rpc\IProducer;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
@@ -18,6 +19,8 @@ use Snowflake\Snowflake;
#[\Attribute(\Attribute::TARGET_CLASS)] class RpcService extends Attribute
{
private array $config;
/**
* RpcClient constructor.
@@ -33,6 +36,7 @@ use Snowflake\Snowflake;
public int $mode = SWOOLE_SOCK_TCP6
)
{
$this->config = ['host' => $this->host, 'port' => $this->port, 'mode' => $this->mode];
}
@@ -45,13 +49,15 @@ use Snowflake\Snowflake;
*/
public function execute(array $handler): mixed
{
// TODO: Change the autogenerated stub
if ($handler[0] instanceof IProducer) {
call_user_func([$handler[0], 'instance']);
}
$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
$rpc->addProducer($this->cmd, $handler, $this->config);
return parent::execute($handler);
}