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
This commit is contained in:
胡俊 2023-07-25 21:17:29 +08:00 committed by GitHub
parent 3c5cb3bc01
commit 7c7f3db772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -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);
}

View File

@ -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)) {

View File

@ -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);