Support path_prefix for node when using rpc-client. (#4576)

Co-authored-by: 李铭昕 <l@hyperf.io>
This commit is contained in:
pandaLIU 2022-04-13 14:55:13 +08:00 committed by GitHub
parent 4d9cd7d17d
commit 070bcf0d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -4,6 +4,9 @@
- [#4677](https://github.com/hyperf/hyperf/pull/4677) Fixed bug that process exit failed when using kafka producer.
## Added
- [#4576](https://github.com/hyperf/hyperf/pull/4576) Support `path_prefix` for `node` when using `rpc-client`.
# v2.2.30 - 2022-04-04

View File

@ -68,7 +68,7 @@ class JsonRpcHttpTransporter implements TransporterInterface
public function send(string $data)
{
$node = $this->getNode();
$uri = $node->host . ':' . $node->port;
$uri = $node->host . ':' . $node->port . $node->pathPrefix;
$schema = value(function () use ($node) {
$schema = 'http';
if (property_exists($node, 'schema')) {

View File

@ -28,10 +28,17 @@ class Node
*/
public $port;
public function __construct(string $host, int $port, int $weight = 0)
/**
* The path prefix, only support protocol `jsonrpc-http`.
* @var string
*/
public $pathPrefix = '';
public function __construct(string $host, int $port, int $weight = 0, string $pathPrefix = '')
{
$this->host = $host;
$this->port = $port;
$this->weight = $weight;
$this->pathPrefix = $pathPrefix;
}
}

View File

@ -217,7 +217,7 @@ abstract class AbstractServiceClient
if (! is_int($item['port'])) {
throw new InvalidArgumentException(sprintf('Invalid node config [%s], the port option has to a integer.', implode(':', $item)));
}
$nodes[] = new Node($item['host'], $item['port']);
$nodes[] = new Node($item['host'], $item['port'], $item['weight'] ?? 0, $item['path_prefix'] ?? '');
}
}
return [$nodes, $refreshCallback];
@ -233,8 +233,7 @@ abstract class AbstractServiceClient
]);
$nodes = [];
foreach ($nodeArray as $node) {
// @TODO Get and set the weight property.
$nodes[] = new Node($node['host'], $node['port']);
$nodes[] = new Node($node['host'], $node['port'], $node['weight'] ?? 0, $node['path_prefix'] ?? '');
}
return $nodes;