diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java index 4f5e849ac7..3a7b1a52cd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java @@ -62,7 +62,7 @@ public abstract class AbstractMethodConfig extends AbstractConfig { /** * The name of mock class which gets called when a service fails to execute - * + *

* note that: the mock doesn't support on the provider side,and the mock is executed when a non-business exception * occurs after a remote service call */ @@ -157,18 +157,20 @@ public abstract class AbstractMethodConfig extends AbstractConfig { } public void setMock(String mock) { - if (mock == null) { - return; - } this.mock = mock; } - public void setMock(Boolean mock) { + /** + * Set the property "mock" + * + * @param mock the value of mock + * @since 2.7.6 + */ + public void setMock(Object mock) { if (mock == null) { - setMock((String) null); - } else { - setMock(mock.toString()); + return; } + this.setMock(String.valueOf(mock)); } public String getMerger() { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index 9810207ad0..4a7c282eb9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -209,8 +209,8 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { } public void completeCompoundConfigs() { - super.completeCompoundConfigs(provider); - if(provider != null) { + super.completeCompoundConfigs(provider); + if (provider != null) { if (protocols == null) { setProtocols(provider.getProtocols()); } @@ -223,8 +223,9 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { if (StringUtils.isEmpty(protocolIds)) { setProtocolIds(provider.getProtocolIds()); } - } + } } + private void convertProtocolIdsToProtocols() { computeValidProtocolIds(); if (StringUtils.isEmpty(protocolIds)) { @@ -361,12 +362,12 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { } @Override - public void setMock(Boolean mock) { + public void setMock(String mock) { throw new IllegalArgumentException("mock doesn't support on provider side"); } @Override - public void setMock(String mock) { + public void setMock(Object mock) { throw new IllegalArgumentException("mock doesn't support on provider side"); } diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java index f26cf0cce1..2e61d22fd5 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java @@ -27,6 +27,13 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.support.FailbackRegistry; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.listener.EventListener; +import com.alibaba.nacos.api.naming.listener.NamingEvent; +import com.alibaba.nacos.api.naming.pojo.Instance; +import com.alibaba.nacos.api.naming.pojo.ListView; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -36,23 +43,14 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.listener.EventListener; -import com.alibaba.nacos.api.naming.listener.NamingEvent; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.api.naming.pojo.ListView; - -import static java.util.Collections.singleton; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; @@ -122,12 +120,9 @@ public class NacosRegistry extends FailbackRegistry { private final NamingService namingService; - private final ConcurrentMap nacosListeners; - public NacosRegistry(URL url, NamingService namingService) { super(url); this.namingService = namingService; - this.nacosListeners = new ConcurrentHashMap<>(); } @Override @@ -215,7 +210,10 @@ public class NacosRegistry extends FailbackRegistry { final Set serviceNames; if (serviceName.isConcrete()) { // is the concrete service name - serviceNames = singleton(serviceName.toString()); + serviceNames = new LinkedHashSet<>(); + serviceNames.add(serviceName.toString()); + // Add the legacy service name since 2.7.6 + serviceNames.add(getLegacySubscribedServiceName(url)); } else { serviceNames = filterServiceNames(serviceName); } @@ -240,6 +238,28 @@ public class NacosRegistry extends FailbackRegistry { return serviceNames; } + /** + * Get the legacy subscribed service name for compatible with Dubbo 2.7.3 and below + * + * @param url {@link URL} + * @return non-null + * @since 2.7.6 + */ + private String getLegacySubscribedServiceName(URL url) { + StringBuilder serviceNameBuilder = new StringBuilder(DEFAULT_CATEGORY); + appendIfPresent(serviceNameBuilder, url, INTERFACE_KEY); + appendIfPresent(serviceNameBuilder, url, VERSION_KEY); + appendIfPresent(serviceNameBuilder, url, GROUP_KEY); + return serviceNameBuilder.toString(); + } + + private void appendIfPresent(StringBuilder target, URL url, String parameterName) { + String parameterValue = url.getParameter(parameterName); + if (!org.apache.commons.lang3.StringUtils.isBlank(parameterValue)) { + target.append(SERVICE_NAME_SEPARATOR).append(parameterValue); + } + } + private boolean isAdminProtocol(URL url) { return ADMIN_PROTOCOL.equals(url.getProtocol()); @@ -398,9 +418,6 @@ public class NacosRegistry extends FailbackRegistry { private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException { - if (nacosListeners.containsKey(serviceName)) { - logger.info("nacosListeners contains serviceName:" + serviceName); - } EventListener eventListener = event -> { if (event instanceof NamingEvent) { NamingEvent e = (NamingEvent) event; @@ -408,7 +425,6 @@ public class NacosRegistry extends FailbackRegistry { } }; namingService.subscribe(serviceName, eventListener); - nacosListeners.put(serviceName, eventListener); } /**