This commit is contained in:
2021-03-24 18:51:07 +08:00
parent 2a35ce9d13
commit 7c7a7f4d6e
+9 -3
View File
@@ -5,6 +5,7 @@ namespace Rpc;
use Exception; use Exception;
use JetBrains\PhpStorm\ArrayShape;
use ReflectionException; use ReflectionException;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Exception\ComponentException; use Snowflake\Exception\ComponentException;
@@ -128,6 +129,10 @@ class Producer extends Component
if ($producer === null) { if ($producer === null) {
throw new Exception('Unknown rpc client config.'); throw new Exception('Unknown rpc client config.');
} }
if (!isset($producer['host'])) {
$producer['host'] = Snowflake::localhost();
}
$producerName = $this->getName($name, $producer); $producerName = $this->getName($name, $producer);
$snowflake = Snowflake::app(); $snowflake = Snowflake::app();
@@ -144,6 +149,7 @@ class Producer extends Component
* @param $producer * @param $producer
* @return array * @return array
*/ */
#[ArrayShape(['class' => "string", 'service' => "", 'config' => ""])]
private function definer($name, $producer): array private function definer($name, $producer): array
{ {
return ['class' => Client::class, 'service' => $name, 'config' => $producer]; return ['class' => Client::class, 'service' => $name, 'config' => $producer];
@@ -163,12 +169,12 @@ class Producer extends Component
/** /**
* @param $name * @param $name
* @param $rand * @param $config
* @return string * @return string
*/ */
private function getName($name, $rand): string private function getName($name, $config): string
{ {
return 'rpc.client.' . $name . '.' . $rand['host']; return 'rpc.client.' . $name . '.' . $config['host'];
} }
} }