You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/06/05 02:53:19 UTC

[dubbo-go-pixiu] branch develop updated: fix: nacos support namespace && group

This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new c7b0e892 fix: nacos support namespace && group
     new a47afd31 Merge pull request #438 from MasterKenway/fix/nacos-group
c7b0e892 is described below

commit c7b0e892ac31276e751c699eb927c50bc9e5312f
Author: MasterKenway <zk...@ikenway.net>
AuthorDate: Sat Jun 4 23:52:44 2022 +0800

    fix: nacos support namespace && group
---
 .../dubboregistry/registry/nacos/interface_listener.go    |  9 ++++++---
 pkg/adapter/dubboregistry/registry/nacos/registry.go      |  8 ++++++++
 pkg/client/dubbo/dubbo.go                                 | 12 +++++++-----
 pkg/model/cluster.go                                      | 15 ++++++++++-----
 samples/dubbogo/simple/nacos/pixiu/conf.yaml              |  8 +++++++-
 .../dubbogo/simple/nacos/server/profiles/dev/server.yml   |  4 ++++
 6 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/pkg/adapter/dubboregistry/registry/nacos/interface_listener.go b/pkg/adapter/dubboregistry/registry/nacos/interface_listener.go
index a1a2de67..fa90a8f1 100644
--- a/pkg/adapter/dubboregistry/registry/nacos/interface_listener.go
+++ b/pkg/adapter/dubboregistry/registry/nacos/interface_listener.go
@@ -32,7 +32,6 @@ import (
 	dubboRegistry "dubbo.apache.org/dubbo-go/v3/registry"
 
 	"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
-	nacosConstant "github.com/nacos-group/nacos-sdk-go/common/constant"
 	"github.com/nacos-group/nacos-sdk-go/vo"
 )
 
@@ -83,6 +82,8 @@ func (z *nacosIntfListener) WatchAndHandle() {
 	z.dubbogoNacosRegistry, err = dubboConfig.NewRegistryConfigBuilder().
 		SetProtocol("nacos").
 		SetAddress(z.addr).
+		SetGroup(z.reg.Group).
+		SetNamespace(z.reg.Namespace).
 		Build().GetInstance(dubboCommon.CONSUMER)
 	if err != nil {
 		logger.Errorf("create nacos registry with address = %s error = %s", z.addr, err)
@@ -101,7 +102,9 @@ func (z *nacosIntfListener) watch() {
 	defer delayTimer.Stop()
 	for {
 		serviceList, err := z.client.GetAllServicesInfo(vo.GetAllServiceInfoParam{
-			PageSize: 100,
+			GroupName: z.reg.Group,
+			NameSpace: z.reg.Namespace,
+			PageSize:  100,
 		})
 		// error handling
 		if err != nil {
@@ -182,7 +185,7 @@ func (z *nacosIntfListener) updateServiceList(serviceList []string) error {
 				sub := &vo.SubscribeParam{
 					ServiceName:       getSubscribeName(url),
 					SubscribeCallback: l.Callback,
-					GroupName:         nacosConstant.DEFAULT_GROUP,
+					GroupName:         z.reg.Group,
 				}
 
 				if err := z.client.Subscribe(sub); err != nil {
diff --git a/pkg/adapter/dubboregistry/registry/nacos/registry.go b/pkg/adapter/dubboregistry/registry/nacos/registry.go
index 69fdf984..981ada4b 100644
--- a/pkg/adapter/dubboregistry/registry/nacos/registry.go
+++ b/pkg/adapter/dubboregistry/registry/nacos/registry.go
@@ -44,6 +44,9 @@ func init() {
 }
 
 type NacosRegistry struct {
+	Group     string
+	Namespace string
+
 	*baseRegistry.BaseRegistry
 	nacosListeners map[registry.RegisteredType]registry.Listener
 	client         naming_client.INamingClient
@@ -76,13 +79,18 @@ func newNacosRegistry(regConfig model.Registry, adapterListener common.RegistryE
 	scs := []nacosConstant.ServerConfig{
 		*nacosConstant.NewServerConfig(addrAndIP[0], uint64(port)),
 	}
+	ccs := nacosConstant.NewClientConfig(nacosConstant.WithNamespaceId(regConfig.Namespace))
 	client, err := clients.NewNamingClient(vo.NacosClientParam{
 		ServerConfigs: scs,
+		ClientConfig:  ccs,
 	})
 	if err != nil {
 		return nil, err
 	}
+
 	nacosRegistry := &NacosRegistry{
+		Group:          regConfig.Group,
+		Namespace:      regConfig.Namespace,
 		client:         client,
 		nacosListeners: make(map[registry.RegisteredType]registry.Listener),
 	}
diff --git a/pkg/client/dubbo/dubbo.go b/pkg/client/dubbo/dubbo.go
index cc3925ab..e2a9774d 100644
--- a/pkg/client/dubbo/dubbo.go
+++ b/pkg/client/dubbo/dubbo.go
@@ -137,11 +137,13 @@ func (dc *Client) Apply() error {
 			v.Protocol = defaultDubboProtocol
 		}
 		rootConfigBuilder.AddRegistry(k, &dg.RegistryConfig{
-			Protocol: v.Protocol,
-			Address:  v.Address,
-			Timeout:  v.Timeout,
-			Username: v.Username,
-			Password: v.Password,
+			Protocol:  v.Protocol,
+			Address:   v.Address,
+			Timeout:   v.Timeout,
+			Username:  v.Username,
+			Password:  v.Password,
+			Namespace: v.Namespace,
+			Group:     v.Group,
 		})
 	}
 	rootConfigBuilder.SetApplication(defaultApplication)
diff --git a/pkg/model/cluster.go b/pkg/model/cluster.go
index 0d83eff3..48416b30 100644
--- a/pkg/model/cluster.go
+++ b/pkg/model/cluster.go
@@ -65,12 +65,17 @@ type (
 	}
 
 	// Registry remote registry where dubbo apis are registered.
+	// Here comes a problem, dubbo protocol proxy does not use the same registry as pixiu,
+	// so any modification to the config, should apply to both `pkg/client/dubbo/dubbo.go`
+	// and `pkg\adapter\dubboregistry\registry`
 	Registry struct {
-		Protocol string `default:"zookeeper" yaml:"protocol" json:"protocol"`
-		Timeout  string `yaml:"timeout" json:"timeout"`
-		Address  string `yaml:"address" json:"address"`
-		Username string `yaml:"username" json:"username"`
-		Password string `yaml:"password" json:"password"`
+		Protocol  string `default:"zookeeper" yaml:"protocol" json:"protocol"`
+		Timeout   string `yaml:"timeout" json:"timeout"`
+		Address   string `yaml:"address" json:"address"`
+		Username  string `yaml:"username" json:"username"`
+		Password  string `yaml:"password" json:"password"`
+		Group     string `default:"DEFAULT_GROUP"  yaml:"group" json:"group"`
+		Namespace string `yaml:"namespace" json:"namespace"`
 	}
 
 	// DiscoveryType
diff --git a/samples/dubbogo/simple/nacos/pixiu/conf.yaml b/samples/dubbogo/simple/nacos/pixiu/conf.yaml
index 9c03d4eb..e5c74f40 100644
--- a/samples/dubbogo/simple/nacos/pixiu/conf.yaml
+++ b/samples/dubbogo/simple/nacos/pixiu/conf.yaml
@@ -48,6 +48,8 @@ static_resources:
                             address: "127.0.0.1:8848"
                             username: ""
                             password: ""
+                            group: test-group
+                            namespace: 3f327741-31ec-43f8-bb4c-e63c44e17b81
   adapters:
     - id: test
       name: dgp.adapter.dubboregistrycenter
@@ -56,4 +58,8 @@ static_resources:
           "nacos":
             protocol: nacos
             address: "127.0.0.1:8848"
-            timeout: "5s"
\ No newline at end of file
+            timeout: "5s"
+            username: ""
+            password: ""
+            group: test-group
+            namespace: 3f327741-31ec-43f8-bb4c-e63c44e17b81
\ No newline at end of file
diff --git a/samples/dubbogo/simple/nacos/server/profiles/dev/server.yml b/samples/dubbogo/simple/nacos/server/profiles/dev/server.yml
index f2e5e447..33659f1c 100644
--- a/samples/dubbogo/simple/nacos/server/profiles/dev/server.yml
+++ b/samples/dubbogo/simple/nacos/server/profiles/dev/server.yml
@@ -26,6 +26,10 @@ dubbo:
       protocol: nacos
       timeout: 3s
       address: 127.0.0.1:8848
+      username: nacos
+      password: nacos
+      group: test-group
+      namespace: 3f327741-31ec-43f8-bb4c-e63c44e17b81
   protocols:
     dubbo:
       name: dubbo