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 2023/07/25 13:17:34 UTC

[dubbo] branch 3.2 updated: multiple registration cannot be achieved when nacos application level registration (#12731)

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

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 7c7f3db772 multiple registration cannot be achieved when nacos application level registration (#12731)
7c7f3db772 is described below

commit 7c7f3db772589932bd58534fba8b1864d46d394b
Author: 胡俊 <hu...@xiaomi.com>
AuthorDate: Tue Jul 25 21:17:29 2023 +0800

    multiple registration cannot be achieved when nacos application level registration (#12731)
    
    * fix nacos register bug
    
    * fix nacos register bug
    
    * fix nacos register bug
    
    * check style
    
    * ServiceDiscoveryRegistryFactory update
---
 .../registry/client/AbstractServiceDiscoveryFactory.java   |  7 ++++++-
 .../registry/client/ServiceDiscoveryRegistryFactory.java   |  5 +++++
 .../dubbo/registry/nacos/NacosServiceDiscoveryFactory.java | 14 ++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
index 57b4213433..469a507510 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
@@ -50,9 +50,14 @@ public abstract class AbstractServiceDiscoveryFactory implements ServiceDiscover
 
     @Override
     public ServiceDiscovery getServiceDiscovery(URL registryURL) {
-        String key = registryURL.toServiceStringWithoutResolving();
+        String key = createRegistryCacheKey(registryURL);
         return ConcurrentHashMapUtils.computeIfAbsent(discoveries, key, k -> createDiscovery(registryURL));
     }
 
+    protected String createRegistryCacheKey(URL url) {
+        return url.toServiceStringWithoutResolving();
+    }
+
     protected abstract ServiceDiscovery createDiscovery(URL registryURL);
+
 }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryFactory.java
index c5d5ab9c53..def02318b0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryFactory.java
@@ -26,6 +26,11 @@ import static org.apache.dubbo.registry.Constants.DEFAULT_REGISTRY;
 
 public class ServiceDiscoveryRegistryFactory extends AbstractRegistryFactory {
 
+    @Override
+    protected String createRegistryCacheKey(URL url) {
+        return url.toFullString();
+    }
+
     @Override
     protected Registry createRegistry(URL url) {
         if (UrlUtils.hasServiceDiscoveryRegistryProtocol(url)) {
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java
index 56e1c26a42..c6a350a3c0 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java
@@ -17,11 +17,25 @@
 package org.apache.dubbo.registry.nacos;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory;
 import org.apache.dubbo.registry.client.ServiceDiscovery;
 
+import static org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE_KEY;
+
 public class NacosServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory {
 
+    @Override
+    protected String createRegistryCacheKey(URL url) {
+        String namespace = url.getParameter(CONFIG_NAMESPACE_KEY);
+        url = URL.valueOf(url.toServiceStringWithoutResolving());
+        if (StringUtils.isNotEmpty(namespace)) {
+            url = url.addParameter(CONFIG_NAMESPACE_KEY, namespace);
+        }
+
+        return url.toFullString();
+    }
+
     @Override
     protected ServiceDiscovery createDiscovery(URL registryURL) {
         return new NacosServiceDiscovery(applicationModel, registryURL);