* 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字段注入异常
This commit is contained in:
parent
0e30d76495
commit
ff14005475
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue