You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlbumenJ (via GitHub)" <gi...@apache.org> on 2023/07/16 12:23:34 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #12731: multiple registration cannot be achieved when nacos application level registration

AlbumenJ commented on code in PR #12731:
URL: https://github.com/apache/dubbo/pull/12731#discussion_r1264674168


##########
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscoveryFactory.java:
##########
@@ -17,11 +17,24 @@
 package org.apache.dubbo.registry.nacos;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
+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
+    public ServiceDiscovery getServiceDiscovery(URL registryURL) {
+        String namespace = registryURL.getParameter(CONFIG_NAMESPACE_KEY);
+        URL url = URL.valueOf(registryURL.toServiceStringWithoutResolving());
+        if (StringUtils.isNotEmpty(namespace)) {
+            url = url.addParameter(CONFIG_NAMESPACE_KEY, namespace);
+        }
+        return ConcurrentHashMapUtils.computeIfAbsent(getDiscoveries(), url.toFullString(), k -> createDiscovery(registryURL));
+    }

Review Comment:
   Create a abstract method `protected String createRegistryCacheKey(URL url)` in `AbstractServiceDiscoveryFactory` would be a better choice, which will make the behavior be consistent with `RegistryFactory`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org