mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Support path_prefix
for node
when using rpc-client
. (#4576)
Co-authored-by: 李铭昕 <l@hyperf.io>
This commit is contained in:
parent
4d9cd7d17d
commit
070bcf0d84
@ -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
|
||||
|
||||
|
@ -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')) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user