Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Polish /apache#5745 : Increasing the stack size in the start.sh

* Polish /apache#5297 : Only one of the multiple registration centers using nacos can register

* Polish /apache#5442 : VERSION_KEY和GROUP_KEY为空时,注册到NACOS的服务名与alibaba实现不一致,导致无法消费

* Polish /apache#5442 : Merge upstream/master

* Polish /apache/dubbo#apache#5239 : Mock字段注入异常

* Polish /apache/dubbo#apache#5239 : Mock字段注入异常
  • Loading branch information
mercyblitz authored and seedeed committed Feb 20, 2020
1 parent 176be46 commit 084fa12
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -157,18 +157,20 @@ public String getMock() {
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ public void checkProtocol() {
}

public void completeCompoundConfigs() {
super.completeCompoundConfigs(provider);
if(provider != null) {
super.completeCompoundConfigs(provider);
if (provider != null) {
if (protocols == null) {
setProtocols(provider.getProtocols());
}
Expand All @@ -223,8 +223,9 @@ public void completeCompoundConfigs() {
if (StringUtils.isEmpty(protocolIds)) {
setProtocolIds(provider.getProtocolIds());
}
}
}
}

private void convertProtocolIdsToProtocols() {
computeValidProtocolIds();
if (StringUtils.isEmpty(protocolIds)) {
Expand Down Expand Up @@ -361,12 +362,12 @@ public void setGeneric(String generic) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
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;
Expand All @@ -36,23 +43,14 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -215,7 +210,10 @@ private Set<String> getServiceNames0(URL url) {
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);
}
Expand All @@ -240,6 +238,28 @@ private Set<String> filterServiceNames(NacosServiceName serviceName) {
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());
Expand Down Expand Up @@ -398,17 +418,13 @@ private List<URL> buildURLs(URL consumerURL, Collection<Instance> instances) {

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;
notifySubscriber(url, listener, e.getInstances());
}
};
namingService.subscribe(serviceName, eventListener);
nacosListeners.put(serviceName, eventListener);
}

/**
Expand Down

0 comments on commit 084fa12

Please sign in to comment.