This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new ff14005 Polish #5442 (#5760)
ff14005 is described below
commit ff14005475dc2e6e1e8c5081abb61e65faef464c
Author: Mercy Ma <[email protected]>
AuthorDate: Thu Feb 20 11:46:14 2020 +0800
Polish #5442 (#5760)
* Polish /apache/dubbo#5745 : Increasing the stack size in the start.sh
* Polish /apache/dubbo#5297 : Only one of the multiple registration centers
using nacos can register
* Polish /apache/dubbo#5442 :
VERSION_KEY和GROUP_KEY为空时,注册到NACOS的服务名与alibaba实现不一致,导致无法消费
* Polish /apache/dubbo#5442 : Merge upstream/master
* Polish /apache/dubbo##5239 : Mock字段注入异常
* Polish /apache/dubbo##5239 : Mock字段注入异常
---
.../apache/dubbo/config/AbstractMethodConfig.java | 18 ++++----
.../org/apache/dubbo/config/ServiceConfigBase.java | 11 ++---
.../apache/dubbo/registry/nacos/NacosRegistry.java | 52 ++++++++++++++--------
3 files changed, 50 insertions(+), 31 deletions(-)
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 4f5e849..3a7b1a5 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
- *
+ * <p>
* 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 9810207..4a7c282 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<T> 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<T> 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<T> 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 f26cf0c..2e61d22 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<String, EventListener> 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<String> 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);
}
/**