From fb9521b2e6649c913995ca96012dd5a4b8a78465 Mon Sep 17 00:00:00 2001 From: theonefx Date: Wed, 23 Jun 2021 16:26:54 +0800 Subject: [PATCH 1/6] remove unused code; make sure param not lost, so that different param calculate different revision. --- .../nacos/registry/NacosServiceRegistry.java | 3 +- .../metadata/DefaultMetadataParamsFilter.java | 55 ------ .../dubbo/metadata/MetadataParamsFilter.java | 35 ---- .../cloud/dubbo/metadata/ServiceInfo.java | 172 ++++-------------- .../dubbo/registry/DubboCloudRegistry.java | 5 +- ....cloud.dubbo.metadata.MetadataParamsFilter | 1 - 6 files changed, 39 insertions(+), 232 deletions(-) delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DefaultMetadataParamsFilter.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MetadataParamsFilter.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/com.alibaba.cloud.dubbo.metadata.MetadataParamsFilter diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java index 16010b373..9b91ce48e 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java @@ -161,7 +161,8 @@ public class NacosServiceRegistry implements ServiceRegistry { String serviceName = registration.getServiceId(); String group = nacosDiscoveryProperties.getGroup(); try { - List instances = namingService().getAllInstances(serviceName, group); + List instances = namingService().getAllInstances(serviceName, + group); for (Instance instance : instances) { if (instance.getIp().equalsIgnoreCase(nacosDiscoveryProperties.getIp()) && instance.getPort() == nacosDiscoveryProperties.getPort()) { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DefaultMetadataParamsFilter.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DefaultMetadataParamsFilter.java deleted file mode 100644 index 53d090f1c..000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DefaultMetadataParamsFilter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.alibaba.cloud.dubbo.metadata; - -import org.apache.dubbo.common.extension.Activate; - -import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.remoting.Constants.CODEC_KEY; -import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY; -import static org.apache.dubbo.remoting.Constants.EXCHANGER_KEY; -import static org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY; -import static org.apache.dubbo.rpc.Constants.DEPRECATED_KEY; -import static org.apache.dubbo.rpc.Constants.MOCK_KEY; -import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.WARMUP_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.WEIGHT_KEY; - -/** - * Copy from org.apache.dubbo.metadata.DefaultMetadataParamsFilter. - * - * @author theonefx - */ -@Activate -public class DefaultMetadataParamsFilter implements MetadataParamsFilter { - - @Override - public String[] serviceParamsIncluded() { - return new String[] { CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, - CONNECTIONS_KEY, DEPRECATED_KEY, GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, - PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, - DUBBO_VERSION_KEY, RELEASE_KEY }; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MetadataParamsFilter.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MetadataParamsFilter.java deleted file mode 100644 index f7b4dc7d1..000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MetadataParamsFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.alibaba.cloud.dubbo.metadata; - -import org.apache.dubbo.common.extension.SPI; - -/** - * Copy from org.apache.dubbo.metadata.MetadataParamsFilter. - * - * @author theonefx - */ -@SPI -public interface MetadataParamsFilter { - - /** - * params that need to be sent to metadata center. - * @return arrays of keys - */ - String[] serviceParamsIncluded(); - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java index a734a8e7e..7e1095f98 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java @@ -20,23 +20,32 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.compiler.support.ClassUtils; -import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.StringUtils; -import static org.apache.dubbo.common.constants.CommonConstants.DOT_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.HOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PASSWORD_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PORT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.USERNAME_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; /** @@ -48,9 +57,6 @@ public class ServiceInfo implements Serializable { private static final long serialVersionUID = -258557978718735302L; - private static ExtensionLoader loader = ExtensionLoader - .getExtensionLoader(MetadataParamsFilter.class); - private String name; private String group; @@ -66,16 +72,6 @@ public class ServiceInfo implements Serializable { // params configured on consumer side, private transient Map consumerParams; - // cached method params - private transient Map> methodParams; - - private transient Map> consumerMethodParams; - - // cached numbers - private transient Map numbers; - - private transient Map> methodNumbers; - // service + group + version private transient String serviceKey; @@ -84,7 +80,20 @@ public class ServiceInfo implements Serializable { private transient URL url; - public ServiceInfo() { + private static final Set IGNORE_KEYS = new HashSet<>(); + static { + IGNORE_KEYS.add(TIMESTAMP_KEY); + IGNORE_KEYS.add(PID_KEY); + IGNORE_KEYS.add(INTERFACE_KEY); + IGNORE_KEYS.add(METHODS_KEY); + IGNORE_KEYS.add(THREADS_KEY); + IGNORE_KEYS.add(QUEUES_KEY); + IGNORE_KEYS.add(TIMEOUT_KEY); + IGNORE_KEYS.add(USERNAME_KEY); + IGNORE_KEYS.add(PASSWORD_KEY); + IGNORE_KEYS.add(HOST_KEY); + IGNORE_KEYS.add(PORT_KEY); + IGNORE_KEYS.add(RETRIES_KEY); } public ServiceInfo(URL url) { @@ -92,40 +101,16 @@ public class ServiceInfo implements Serializable { url.getParameter(VERSION_KEY), url.getProtocol(), url.getPath(), null); this.url = url; - Map params = new HashMap<>(); - List filters = loader.getActivateExtension(url, - "params-filter"); - for (MetadataParamsFilter filter : filters) { - String[] paramsIncluded = filter.serviceParamsIncluded(); - if (ArrayUtils.isNotEmpty(paramsIncluded)) { - for (String p : paramsIncluded) { - String value = url.getParameter(p); - if (StringUtils.isNotEmpty(value) && params.get(p) == null) { - params.put(p, value); - } - String[] methods = url.getParameter(METHODS_KEY, (String[]) null); - if (methods != null) { - for (String method : methods) { - String mValue = getMethodParameterStrict(url, method, p); - if (StringUtils.isNotEmpty(mValue)) { - params.put(method + DOT_SEPARATOR + p, mValue); - } - } - } - } + Map params = new TreeMap<>(); + url.getParameters().forEach((k, v) -> { + if (IGNORE_KEYS.contains(k)) { + return; } - } + params.put(k, v); + }); this.params = params; } - public String getMethodParameterStrict(URL url, String method, String key) { - Map keyMap = url.getMethodParameters().get(method); - String value = null; - if (keyMap != null) { - value = keyMap.get(key); - } - return value; - } public ServiceInfo(String name, String group, String version, String protocol, String path, Map params) { @@ -207,17 +192,6 @@ public class ServiceInfo implements Serializable { this.params = params; } - public Map getAllParams() { - if (consumerParams != null) { - Map allParams = new HashMap<>( - (int) ((params.size() + consumerParams.size()) / 0.75f + 1)); - allParams.putAll(params); - allParams.putAll(consumerParams); - return allParams; - } - return params; - } - public String getParameter(String key) { if (consumerParams != null) { String value = consumerParams.get(key); @@ -228,54 +202,12 @@ public class ServiceInfo implements Serializable { return params.get(key); } - public String getMethodParameter(String method, String key, String defaultValue) { - if (methodParams == null) { - methodParams = URL.toMethodParameters(params); - consumerMethodParams = URL.toMethodParameters(consumerParams); - } - - String value = getMethodParameter(method, key, consumerMethodParams); - if (value != null) { - return value; - } - value = getMethodParameter(method, key, methodParams); - return value == null ? defaultValue : value; - } - - private String getMethodParameter(String method, String key, - Map> map) { - Map keyMap = map.get(method); - String value = null; - if (keyMap != null) { - value = keyMap.get(key); - } - if (StringUtils.isEmpty(value)) { - value = getParameter(key); - } - return value; - } - - public boolean hasMethodParameter(String method, String key) { - String value = this.getMethodParameter(method, key, (String) null); - return StringUtils.isNotEmpty(value); - } - - public boolean hasMethodParameter(String method) { - if (methodParams == null) { - methodParams = URL.toMethodParameters(params); - consumerMethodParams = URL.toMethodParameters(consumerParams); - } - - return consumerMethodParams.containsKey(method) - || methodParams.containsKey(method); - } - public String toDescString() { return this.getMatchKey() + getMethodSignaturesString() + getParams(); } private String getMethodSignaturesString() { - SortedSet methodStrings = new TreeSet(); + SortedSet methodStrings = new TreeSet<>(); Method[] methods = ClassUtils.forName(name).getMethods(); for (Method method : methods) { @@ -284,40 +216,6 @@ public class ServiceInfo implements Serializable { return methodStrings.toString(); } - public void addParameter(String key, String value) { - if (consumerParams != null) { - this.consumerParams.put(key, value); - } - } - - public void addParameterIfAbsent(String key, String value) { - if (consumerParams != null) { - this.consumerParams.putIfAbsent(key, value); - } - } - - public void addConsumerParams(Map params) { - // copy once for one service subscription - if (consumerParams == null) { - consumerParams = new HashMap<>(params); - } - } - - public Map getNumbers() { - // concurrent initialization is tolerant - if (numbers == null) { - numbers = new ConcurrentHashMap<>(); - } - return numbers; - } - - public Map> getMethodNumbers() { - if (methodNumbers == null) { // concurrent initialization is tolerant - methodNumbers = new ConcurrentHashMap<>(); - } - return methodNumbers; - } - public URL getUrl() { return url; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java index f02ebe1a2..f207d7994 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java @@ -244,9 +244,8 @@ public class DubboCloudRegistry extends FailbackRegistry String appName = event.getServiceName(); - List instances = filter( - event.getServiceInstances() != null ? event.getServiceInstances() - : Collections.emptyList()); + List instances = filter(event.getServiceInstances() != null + ? event.getServiceInstances() : Collections.emptyList()); Set subscribedServiceNames = getServices(null); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/com.alibaba.cloud.dubbo.metadata.MetadataParamsFilter b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/com.alibaba.cloud.dubbo.metadata.MetadataParamsFilter deleted file mode 100644 index ce4f0db1e..000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/com.alibaba.cloud.dubbo.metadata.MetadataParamsFilter +++ /dev/null @@ -1 +0,0 @@ -default=com.alibaba.cloud.dubbo.metadata.DefaultMetadataParamsFilter \ No newline at end of file From c448027f34cdab68a740877e410b1406eca199ed Mon Sep 17 00:00:00 2001 From: theonefx Date: Wed, 23 Jun 2021 17:19:10 +0800 Subject: [PATCH 2/6] add spring-cloud-starter-bootstrap to compatible with spring boot bootstrap --- .../cloud/dubbo/metadata/ServiceInfo.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java index 7e1095f98..add184c4f 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceInfo.java @@ -34,18 +34,10 @@ import org.apache.dubbo.common.utils.StringUtils; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.HOST_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PASSWORD_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PORT_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.USERNAME_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; /** @@ -86,14 +78,6 @@ public class ServiceInfo implements Serializable { IGNORE_KEYS.add(PID_KEY); IGNORE_KEYS.add(INTERFACE_KEY); IGNORE_KEYS.add(METHODS_KEY); - IGNORE_KEYS.add(THREADS_KEY); - IGNORE_KEYS.add(QUEUES_KEY); - IGNORE_KEYS.add(TIMEOUT_KEY); - IGNORE_KEYS.add(USERNAME_KEY); - IGNORE_KEYS.add(PASSWORD_KEY); - IGNORE_KEYS.add(HOST_KEY); - IGNORE_KEYS.add(PORT_KEY); - IGNORE_KEYS.add(RETRIES_KEY); } public ServiceInfo(URL url) { @@ -111,7 +95,6 @@ public class ServiceInfo implements Serializable { this.params = params; } - public ServiceInfo(String name, String group, String version, String protocol, String path, Map params) { this.name = name; From 3009b162a0b78a0de6ba19336d9cad1f8c57c461 Mon Sep 17 00:00:00 2001 From: theonefx Date: Thu, 24 Jun 2021 20:55:41 +0800 Subject: [PATCH 3/6] add a router to make sure that use revision when invoke DubboMetadataService --- .../dubbo/metadata/RevisionResolver.java | 21 +++++- .../DubboServiceMetadataRepository.java | 7 +- .../dubbo/registry/DubboCloudRegistry.java | 15 +--- .../GenearalServiceSubscribeHandler.java | 24 +++++-- .../MetadataServiceSubscribeHandler.java | 10 +++ .../service/DubboMetadataServiceProxy.java | 1 + .../MetadataServiceRevisionRouterFactory.java | 69 +++++++++++++++++++ .../cloud/dubbo/util/DubboMetadataUtils.java | 8 ++- ...org.apache.dubbo.rpc.cluster.RouterFactory | 1 + 9 files changed, 128 insertions(+), 28 deletions(-) create mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java create mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RevisionResolver.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RevisionResolver.java index 53f9f1bf4..8ffc18457 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RevisionResolver.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RevisionResolver.java @@ -18,10 +18,14 @@ package com.alibaba.cloud.dubbo.metadata; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Map; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.springframework.cloud.client.ServiceInstance; + +import static com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository.EXPORTED_SERVICES_REVISION_PROPERTY_NAME; import static java.nio.charset.StandardCharsets.UTF_8; /** @@ -31,10 +35,15 @@ import static java.nio.charset.StandardCharsets.UTF_8; */ public final class RevisionResolver { - private static final Logger logger = LoggerFactory.getLogger(RevisionResolver.class); + /** + * The param key in url. + */ + public static final String SCA_REVSION_KEY = "sca_revision"; private static final String EMPTY_REVISION = "0"; + private static final Logger logger = LoggerFactory.getLogger(RevisionResolver.class); + private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; @@ -71,4 +80,14 @@ public final class RevisionResolver { return new String(str); } + public static String getRevision(ServiceInstance instance) { + Map metadata = instance.getMetadata(); + String revision = metadata.get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME); + + if (revision == null) { + revision = RevisionResolver.getEmptyRevision(); + } + return revision; + } + } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java index 8b687cd19..2579b12ab 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java @@ -106,11 +106,6 @@ public class DubboServiceMetadataRepository */ public static String EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"; - /** - * The {@link String#format(String, Object...) pattern} of dubbo protocols port. - */ - public static final String DUBBO_PROTOCOLS_PORT_PROPERTY_NAME_PATTERN = "dubbo.protocols.%s.port"; - private final Logger logger = LoggerFactory.getLogger(getClass()); private final ObjectMapper objectMapper = new ObjectMapper(); @@ -150,7 +145,7 @@ public class DubboServiceMetadataRepository * Key is application name Value is Map<RequestMetadata, * DubboRestServiceMetadata>. */ - private Map> dubboRestServiceMetadataRepository = newHashMap(); + private final Map> dubboRestServiceMetadataRepository = newHashMap(); // =============================================================== // diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java index f207d7994..643acdf1a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboCloudRegistry.java @@ -47,7 +47,6 @@ import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; -import static com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository.EXPORTED_SERVICES_REVISION_PROPERTY_NAME; import static java.util.Collections.emptyList; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; @@ -130,7 +129,7 @@ public class DubboCloudRegistry extends FailbackRegistry .computeIfAbsent(appName, k -> new HashMap<>()); for (ServiceInstance instance : instances) { - String revision = getRevision(instance); + String revision = RevisionResolver.getRevision(instance); List list = map.computeIfAbsent(revision, k -> new ArrayList<>()); list.add(instance); @@ -262,7 +261,7 @@ public class DubboCloudRegistry extends FailbackRegistry } // group by revision Map> newGroup = instances.stream() - .collect(Collectors.groupingBy(this::getRevision)); + .collect(Collectors.groupingBy(RevisionResolver::getRevision)); synchronized (this) { @@ -439,16 +438,6 @@ public class DubboCloudRegistry extends FailbackRegistry return true; } - String getRevision(ServiceInstance instance) { - Map metadata = instance.getMetadata(); - String revision = metadata.get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME); - - if (revision == null) { - revision = RevisionResolver.getEmptyRevision(); - } - return revision; - } - private List filter(Collection serviceInstances) { return serviceInstances.stream().filter(this::isDubboServiceInstance) .collect(Collectors.toList()); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/GenearalServiceSubscribeHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/GenearalServiceSubscribeHandler.java index a2f3ca4f7..b92e8c4e5 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/GenearalServiceSubscribeHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/GenearalServiceSubscribeHandler.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.alibaba.cloud.dubbo.metadata.RevisionResolver; import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; import com.alibaba.cloud.dubbo.service.DubboMetadataService; import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; @@ -34,9 +35,11 @@ import com.alibaba.cloud.dubbo.util.JSONUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.rpc.RpcContext; import org.springframework.cloud.client.ServiceInstance; +import static com.alibaba.cloud.dubbo.metadata.RevisionResolver.SCA_REVSION_KEY; import static java.util.Collections.emptyList; import static org.apache.dubbo.common.URLBuilder.from; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; @@ -50,6 +53,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; */ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHandler { + /** + * the provider which can provide service of the url. {appName, [revisions]} + */ private final Map> providers = new HashMap<>(); private final Map urlTemplateMap = new HashMap<>(); @@ -117,7 +123,7 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan public void init(String appName, String revision, List instanceList) { - List urls = getTemplateExportedURLs(url, instanceList); + List urls = getTemplateExportedURLs(url, revision, instanceList); if (urls != null && urls.size() > 0) { addAppNameWithRevision(appName, revision); setUrlTemplate(appName, revision, urls); @@ -170,7 +176,7 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan String host = serviceInstance.getHost(); String appName = serviceInstance.getServiceId(); - String revision = registry.getRevision(serviceInstance); + String revision = RevisionResolver.getRevision(serviceInstance); URL template = urlTemplateMap.get(getAppRevisionKey(appName, revision)); @@ -225,7 +231,7 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan return urlsCloneTo; } - private List getTemplateExportedURLs(URL subscribedURL, + private List getTemplateExportedURLs(URL subscribedURL, String revision, List serviceInstances) { DubboMetadataService dubboMetadataService = getProxy(serviceInstances); @@ -233,7 +239,8 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan List templateExportedURLs = emptyList(); if (dubboMetadataService != null) { - templateExportedURLs = getExportedURLs(dubboMetadataService, subscribedURL); + templateExportedURLs = getExportedURLs(dubboMetadataService, revision, + subscribedURL); } else { if (logger.isWarnEnabled()) { @@ -253,14 +260,17 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan } private List getExportedURLs(DubboMetadataService dubboMetadataService, - URL subscribedURL) { + String revision, URL subscribedURL) { String serviceInterface = subscribedURL.getServiceInterface(); String group = subscribedURL.getParameter(GROUP_KEY); String version = subscribedURL.getParameter(VERSION_KEY); - // The subscribed protocol may be null - String subscribedProtocol = subscribedURL.getParameter(PROTOCOL_KEY); + + RpcContext.getContext().setAttachment(SCA_REVSION_KEY, revision); String exportedURLsJSON = dubboMetadataService.getExportedURLs(serviceInterface, group, version); + + // The subscribed protocol may be null + String subscribedProtocol = subscribedURL.getParameter(PROTOCOL_KEY); return jsonUtils.toURLs(exportedURLsJSON).stream() .filter(exportedURL -> subscribedProtocol == null || subscribedProtocol.equalsIgnoreCase(exportedURL.getProtocol())) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java index 9a9f99325..089c986da 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java @@ -20,12 +20,15 @@ import java.util.List; import com.alibaba.cloud.dubbo.util.DubboMetadataUtils; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.registry.NotifyListener; import org.springframework.cloud.client.ServiceInstance; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; +import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY; /** * @author theonefx @@ -44,6 +47,7 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan this.dubboMetadataUtils = dubboMetadataUtils; } + @Override public void doInit() { logger.debug("Subscription app {} MetadataService handler init", appName); List serviceInstances = registry.getServiceInstances(appName); @@ -69,6 +73,12 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan List urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances, serviceInterface, version, protocol); + URLBuilder builder = new URLBuilder(); + builder.setProtocol(ROUTE_PROTOCOL); + builder.addParameter(ROUTER_KEY, "revisionRouter"); + + urls.add(builder.build()); + notifyAllSubscribedURLs(subscribedURL, urls, listener); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java index b6f65fa67..c653c52ec 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java @@ -125,6 +125,7 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab private DubboMetadataService createProxyIfAbsent(URL dubboMetadataServiceURL) { String serviceName = dubboMetadataServiceURL.getParameter(APPLICATION_KEY); String version = dubboMetadataServiceURL.getParameter(VERSION_KEY); + // Initialize DubboMetadataService with right version return createProxyIfAbsent(serviceName, version); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java new file mode 100644 index 000000000..340acb32b --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java @@ -0,0 +1,69 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.dubbo.service; + +import java.util.ArrayList; +import java.util.List; + +import com.alibaba.cloud.commons.lang.StringUtils; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.cluster.Router; +import org.apache.dubbo.rpc.cluster.RouterFactory; +import org.apache.dubbo.rpc.cluster.router.AbstractRouter; + +import static com.alibaba.cloud.dubbo.metadata.RevisionResolver.SCA_REVSION_KEY; + +/** + * @author theonefx + */ +public class MetadataServiceRevisionRouterFactory implements RouterFactory { + + @Override + public Router getRouter(URL url) { + return new AbstractRouter() { + @Override + public List> route(List> invokers, URL url, + Invocation invocation) throws RpcException { + if (!DubboMetadataService.class.getName() + .equalsIgnoreCase(url.getServiceInterface())) { + return invokers; + } + + String revision = invocation.getAttachment(SCA_REVSION_KEY); + + if (StringUtils.isEmpty(revision)) { + return invokers; + } + + List> list = new ArrayList<>(invokers.size()); + + for (Invoker invoker : invokers) { + if (StringUtils.equals(revision, + invoker.getUrl().getParameter(SCA_REVSION_KEY))) { + list.add(invoker); + } + } + + return list; + } + }; + } + +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/DubboMetadataUtils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/DubboMetadataUtils.java index af3c59460..acb4c2a14 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/DubboMetadataUtils.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/DubboMetadataUtils.java @@ -21,12 +21,14 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import com.alibaba.cloud.dubbo.metadata.RevisionResolver; import com.alibaba.cloud.dubbo.service.DubboMetadataService; import org.apache.dubbo.common.URL; import org.springframework.cloud.client.ServiceInstance; import org.springframework.core.env.Environment; +import static com.alibaba.cloud.dubbo.metadata.RevisionResolver.SCA_REVSION_KEY; import static java.lang.String.format; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URLS_PROPERTY_NAME; @@ -74,7 +76,11 @@ public class DubboMetadataUtils { public List getDubboMetadataServiceURLs(ServiceInstance serviceInstance) { Map metadata = serviceInstance.getMetadata(); String dubboURLsJSON = metadata.get(METADATA_SERVICE_URLS_PROPERTY_NAME); - return jsonUtils.toURLs(dubboURLsJSON); + List urls = jsonUtils.toURLs(dubboURLsJSON); + String revision = RevisionResolver.getRevision(serviceInstance); + urls = urls.stream().map(url -> url.addParameter(SCA_REVSION_KEY, revision)) + .collect(Collectors.toList()); + return urls; } /** diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory new file mode 100644 index 000000000..f56d67e6d --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory @@ -0,0 +1 @@ +revisionRouter=com.alibaba.cloud.dubbo.service.MetadataServiceRevisionRouterFactory \ No newline at end of file From 374964d8dce75f04c3471e48a421892a1e5d0d16 Mon Sep 17 00:00:00 2001 From: theonefx Date: Thu, 24 Jun 2021 21:49:21 +0800 Subject: [PATCH 4/6] add router url when urls is not empty --- .../registry/MetadataServiceSubscribeHandler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java index 089c986da..50ee604e8 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java @@ -73,11 +73,12 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan List urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances, serviceInterface, version, protocol); - URLBuilder builder = new URLBuilder(); - builder.setProtocol(ROUTE_PROTOCOL); - builder.addParameter(ROUTER_KEY, "revisionRouter"); - - urls.add(builder.build()); + if (urls.size() > 0) { + URLBuilder builder = new URLBuilder(); + builder.setProtocol(ROUTE_PROTOCOL); + builder.addParameter(ROUTER_KEY, "revisionRouter"); + urls.add(builder.build()); + } notifyAllSubscribedURLs(subscribedURL, urls, listener); } From 5f7ddab58e43262f57577667c9b23a038bdd2d1d Mon Sep 17 00:00:00 2001 From: theonefx Date: Fri, 25 Jun 2021 17:49:58 +0800 Subject: [PATCH 5/6] avoid defult router impact DubboMetadataService works --- .../registry/MetadataServiceSubscribeHandler.java | 12 ++++++------ .../dubbo/service/DubboGenericServiceFactory.java | 3 +++ .../MetadataServiceRevisionRouterFactory.java | 6 ++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java index 50ee604e8..6e0009ab2 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java @@ -73,12 +73,12 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan List urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances, serviceInterface, version, protocol); - if (urls.size() > 0) { - URLBuilder builder = new URLBuilder(); - builder.setProtocol(ROUTE_PROTOCOL); - builder.addParameter(ROUTER_KEY, "revisionRouter"); - urls.add(builder.build()); - } +// if (urls.size() > 0) { +// URLBuilder builder = new URLBuilder(); +// builder.setProtocol(ROUTE_PROTOCOL); +// builder.addParameter(ROUTER_KEY, "revisionRouter"); +// urls.add(builder.build()); +// } notifyAllSubscribedURLs(subscribedURL, urls, listener); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java index d1a68c5f0..9ba24343d 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java @@ -78,6 +78,9 @@ public class DubboGenericServiceFactory { String interfaceName = serviceClass.getName(); ReferenceBean referenceBean = build(interfaceName, version, serviceName, emptyMap()); + if (DubboMetadataService.class == serviceClass) { + referenceBean.setRouter("-default,revisionRouter"); + } return referenceBean.get(); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java index 340acb32b..9d47c53b7 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/MetadataServiceRevisionRouterFactory.java @@ -28,6 +28,8 @@ import org.apache.dubbo.rpc.cluster.Router; import org.apache.dubbo.rpc.cluster.RouterFactory; import org.apache.dubbo.rpc.cluster.router.AbstractRouter; +import org.springframework.util.CollectionUtils; + import static com.alibaba.cloud.dubbo.metadata.RevisionResolver.SCA_REVSION_KEY; /** @@ -41,6 +43,10 @@ public class MetadataServiceRevisionRouterFactory implements RouterFactory { @Override public List> route(List> invokers, URL url, Invocation invocation) throws RpcException { + if (CollectionUtils.isEmpty(invokers)) { + return invokers; + } + if (!DubboMetadataService.class.getName() .equalsIgnoreCase(url.getServiceInterface())) { return invokers; From d69f66cc3e227a641dab61a2ca05224197714702 Mon Sep 17 00:00:00 2001 From: theonefx Date: Fri, 25 Jun 2021 18:13:56 +0800 Subject: [PATCH 6/6] avoid defult router impact DubboMetadataService works --- .../registry/MetadataServiceSubscribeHandler.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java index 6e0009ab2..014131cd1 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/MetadataServiceSubscribeHandler.java @@ -20,15 +20,12 @@ import java.util.List; import com.alibaba.cloud.dubbo.util.DubboMetadataUtils; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.registry.NotifyListener; import org.springframework.cloud.client.ServiceInstance; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; -import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY; /** * @author theonefx @@ -73,13 +70,6 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan List urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances, serviceInterface, version, protocol); -// if (urls.size() > 0) { -// URLBuilder builder = new URLBuilder(); -// builder.setProtocol(ROUTE_PROTOCOL); -// builder.addParameter(ROUTER_KEY, "revisionRouter"); -// urls.add(builder.build()); -// } - notifyAllSubscribedURLs(subscribedURL, urls, listener); }