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.git


The following commit(s) were added to refs/heads/develop by this push:
     new 761f0e06d Fix: Same address cannot distinguish different registry 
center (#2784)
761f0e06d is described below

commit 761f0e06d6446a129297823c8489b3a097c7e6bc
Author: 1kasa <[email protected]>
AuthorDate: Sat Mar 1 22:21:32 2025 +0800

    Fix: Same address cannot distinguish different registry center (#2784)
    
    * fix: Same address cannot distinguish different registry center
    
    * fix: Same address cannot distinguish different registry center
    
    * registry.namespace is set to a constant,
---
 registry/protocol/protocol.go | 10 ++++++++--
 remoting/nacos/builder.go     |  4 ++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go
index bba36151f..b760bcc85 100644
--- a/registry/protocol/protocol.go
+++ b/registry/protocol/protocol.go
@@ -80,14 +80,20 @@ func newRegistryProtocol() *registryProtocol {
 
 func (proto *registryProtocol) getRegistry(registryUrl *common.URL) 
registry.Registry {
        var err error
-       reg, loaded := proto.registries.Load(registryUrl.PrimitiveURL)
+
+       namespace := registryUrl.GetParam(constant.RegistryNamespaceKey, "")
+       cacheKey := registryUrl.PrimitiveURL
+       if namespace != "" {
+               cacheKey = cacheKey + "?" + constant.NacosNamespaceID + "=" + 
namespace
+       }
+       reg, loaded := proto.registries.Load(cacheKey)
        if !loaded {
                reg, err = extension.GetRegistry(registryUrl.Protocol, 
registryUrl)
                if err != nil {
                        logger.Errorf("Registry can not connect success, 
program is going to panic.Error message is %s", err.Error())
                        panic(err)
                }
-               proto.registries.Store(registryUrl.PrimitiveURL, reg)
+               proto.registries.Store(cacheKey, reg)
        }
        return reg.(registry.Registry)
 }
diff --git a/remoting/nacos/builder.go b/remoting/nacos/builder.go
index 2de736519..20807112d 100644
--- a/remoting/nacos/builder.go
+++ b/remoting/nacos/builder.go
@@ -122,5 +122,9 @@ func NewNacosClientByURL(url *common.URL) 
(*nacosClient.NacosNamingClient, error
                return nil, perrors.New("nacos client name must set")
        }
        logger.Infof("[Nacos Client] New nacos client with config = %+v", scs)
+       namespaceID := url.GetParam(constant.NacosNamespaceID, "")
+       if len(namespaceID) > 0 {
+               clientName += namespaceID
+       }
        return nacosClient.NewNacosNamingClient(clientName, true, scs, cc)
 }

Reply via email to