Skip to content

Commit

Permalink
Support grpc for nacos v2 (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Jul 10, 2023
1 parent cc5f7c7 commit f69666f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"hyperf/framework": "~3.0.0",
"hyperf/support": "~3.0.1"
},
"suggests": {
"google/protobuf": "Required to use nacos v2 grpc apis.(~3.0.0)",
"hyperf/grpc": "Required to use nacos v2 grpc apis.(~3.0.0)",
"hyperf/http2-client": "Required to use nacos v2 grpc apis.(~3.0.0)"
},
"autoload": {
"psr-4": {
"FriendsOfHyperf\\Confd\\": "src/"
Expand Down
5 changes: 5 additions & 0 deletions publish/confd.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
'guzzle' => [
'config' => ['timeout' => 3, 'connect_timeout' => 1],
],
// Only support for nacos v2.
'grpc' => [
'enable' => false,
'heartbeat' => 10,
],
],
'listener_config' => [
'mysql' => [
Expand Down
7 changes: 6 additions & 1 deletion src/Driver/Nacos.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Nacos\Application;
use Hyperf\Nacos\Config;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;

use function Hyperf\Collection\collect;
Expand All @@ -28,7 +29,11 @@ class Nacos implements DriverInterface

public function __construct(private ContainerInterface $container, private ConfigInterface $config, private StdoutLoggerInterface $logger)
{
$config = $this->config->get('confd.drivers.nacos.client', []);
$config = $this->config->get('confd.drivers.nacos.client') ?: $this->config->get('nacos', []);

if (empty($config)) {
throw new InvalidArgumentException('Nacos config is invalid.');
}

$this->client = make(NacosClient::class, [
'config' => $this->buildNacosConfig($config),
Expand Down

0 comments on commit f69666f

Please sign in to comment.