改名
This commit is contained in:
@@ -33,8 +33,8 @@ use Snowflake\Snowflake;
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
public string $cmd,
|
public string $cmd,
|
||||||
public int $port,
|
public int $port,
|
||||||
public int $timeout = 1,
|
public int $timeout,
|
||||||
public int $mode = SWOOLE_SOCK_TCP6
|
public int $mode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->config = ['port' => $port, 'mode' => $mode, 'timeout' => $timeout];
|
$this->config = ['port' => $port, 'mode' => $mode, 'timeout' => $timeout];
|
||||||
@@ -54,10 +54,6 @@ use Snowflake\Snowflake;
|
|||||||
$rpc = Snowflake::app()->getRpc();
|
$rpc = Snowflake::app()->getRpc();
|
||||||
$rpc->addProducer($this->cmd, $handler, $this->config);
|
$rpc->addProducer($this->cmd, $handler, $this->config);
|
||||||
|
|
||||||
if ($handler[0] instanceof IProducer) {
|
|
||||||
$handler[0]->initClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::execute($handler);
|
return parent::execute($handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ namespace Rpc;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
use Swoole;
|
|
||||||
use Snowflake\Core\Json;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Exception\ConfigException;
|
|
||||||
use Swoole\Coroutine\Client as CClient;
|
use Swoole\Coroutine\Client as CClient;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -25,7 +25,7 @@ class Producer extends Component
|
|||||||
private array $consumers = [];
|
private array $consumers = [];
|
||||||
|
|
||||||
|
|
||||||
private array $cmds = [];
|
private array $cods = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +57,7 @@ class Producer extends Component
|
|||||||
|
|
||||||
$name = $this->classAlias[$class];
|
$name = $this->classAlias[$class];
|
||||||
|
|
||||||
$this->cmds[$name . '.' . $cmd] = $handler;
|
$this->cods[$name . '.' . $cmd] = $handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class Producer extends Component
|
|||||||
*/
|
*/
|
||||||
public function dispatch($cmd, mixed ...$params): mixed
|
public function dispatch($cmd, mixed ...$params): mixed
|
||||||
{
|
{
|
||||||
$handler = $this->cmds[$cmd] ?? null;
|
$handler = $this->cods[$cmd] ?? null;
|
||||||
if (empty($handler)) {
|
if (empty($handler)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,11 @@ class Producer extends Component
|
|||||||
|
|
||||||
$snowflake = Snowflake::app();
|
$snowflake = Snowflake::app();
|
||||||
if (!$snowflake->has($producerName)) {
|
if (!$snowflake->has($producerName)) {
|
||||||
return $snowflake->set($producerName, ['class' => Client::class, 'config' => $producer]);
|
return $snowflake->set($producerName, [
|
||||||
|
'class' => Client::class,
|
||||||
|
'service' => $name,
|
||||||
|
'config' => $producer
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
return $snowflake->get($producerName);
|
return $snowflake->get($producerName);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user