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:
parent
3c5cb3bc01
commit
7c7f3db772
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue