Merge pull request #2121 from theonefx/master

Ensure that URL for different parameters can be computed to different revision
pull/2135/head
TheoneFx 4 years ago committed by GitHub
commit bfabf9eea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -161,7 +161,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
String serviceName = registration.getServiceId();
String group = nacosDiscoveryProperties.getGroup();
try {
List<Instance> instances = namingService().getAllInstances(serviceName, group);
List<Instance> instances = namingService().getAllInstances(serviceName,
group);
for (Instance instance : instances) {
if (instance.getIp().equalsIgnoreCase(nacosDiscoveryProperties.getIp())
&& instance.getPort() == nacosDiscoveryProperties.getPort()) {

@ -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 <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@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 };
}
}

@ -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 <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@SPI
public interface MetadataParamsFilter {
/**
* params that need to be sent to metadata center.
* @return arrays of keys
*/
String[] serviceParamsIncluded();
}

@ -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<String, String> metadata = instance.getMetadata();
String revision = metadata.get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME);
if (revision == null) {
revision = RevisionResolver.getEmptyRevision();
}
return revision;
}
}

@ -20,23 +20,24 @@ 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.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
/**
@ -48,9 +49,6 @@ public class ServiceInfo implements Serializable {
private static final long serialVersionUID = -258557978718735302L;
private static ExtensionLoader<MetadataParamsFilter> loader = ExtensionLoader
.getExtensionLoader(MetadataParamsFilter.class);
private String name;
private String group;
@ -66,16 +64,6 @@ public class ServiceInfo implements Serializable {
// params configured on consumer side,
private transient Map<String, String> consumerParams;
// cached method params
private transient Map<String, Map<String, String>> methodParams;
private transient Map<String, Map<String, String>> consumerMethodParams;
// cached numbers
private transient Map<String, Number> numbers;
private transient Map<String, Map<String, Number>> methodNumbers;
// service + group + version
private transient String serviceKey;
@ -84,7 +72,12 @@ public class ServiceInfo implements Serializable {
private transient URL url;
public ServiceInfo() {
private static final Set<String> 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);
}
public ServiceInfo(URL url) {
@ -92,41 +85,16 @@ public class ServiceInfo implements Serializable {
url.getParameter(VERSION_KEY), url.getProtocol(), url.getPath(), null);
this.url = url;
Map<String, String> params = new HashMap<>();
List<MetadataParamsFilter> 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<String, String> 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<String, String> 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<String, String> params) {
this.name = name;
@ -207,17 +175,6 @@ public class ServiceInfo implements Serializable {
this.params = params;
}
public Map<String, String> getAllParams() {
if (consumerParams != null) {
Map<String, String> 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 +185,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<String, Map<String, String>> map) {
Map<String, String> 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<String> methodStrings = new TreeSet();
SortedSet<String> methodStrings = new TreeSet<>();
Method[] methods = ClassUtils.forName(name).getMethods();
for (Method method : methods) {
@ -284,40 +199,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<String, String> params) {
// copy once for one service subscription
if (consumerParams == null) {
consumerParams = new HashMap<>(params);
}
}
public Map<String, Number> getNumbers() {
// concurrent initialization is tolerant
if (numbers == null) {
numbers = new ConcurrentHashMap<>();
}
return numbers;
}
public Map<String, Map<String, Number>> getMethodNumbers() {
if (methodNumbers == null) { // concurrent initialization is tolerant
methodNumbers = new ConcurrentHashMap<>();
}
return methodNumbers;
}
public URL getUrl() {
return url;
}

@ -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&lt;RequestMetadata,
* DubboRestServiceMetadata&gt;.
*/
private Map<String, Map<RequestMetadataMatcher, DubboRestServiceMetadata>> dubboRestServiceMetadataRepository = newHashMap();
private final Map<String, Map<RequestMetadataMatcher, DubboRestServiceMetadata>> dubboRestServiceMetadataRepository = newHashMap();
// =============================================================== //

@ -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<ServiceInstance> list = map.computeIfAbsent(revision,
k -> new ArrayList<>());
list.add(instance);
@ -244,9 +243,8 @@ public class DubboCloudRegistry extends FailbackRegistry
String appName = event.getServiceName();
List<ServiceInstance> instances = filter(
event.getServiceInstances() != null ? event.getServiceInstances()
: Collections.emptyList());
List<ServiceInstance> instances = filter(event.getServiceInstances() != null
? event.getServiceInstances() : Collections.emptyList());
Set<String> subscribedServiceNames = getServices(null);
@ -263,7 +261,7 @@ public class DubboCloudRegistry extends FailbackRegistry
}
// group by revision
Map<String, List<ServiceInstance>> newGroup = instances.stream()
.collect(Collectors.groupingBy(this::getRevision));
.collect(Collectors.groupingBy(RevisionResolver::getRevision));
synchronized (this) {
@ -440,16 +438,6 @@ public class DubboCloudRegistry extends FailbackRegistry
return true;
}
String getRevision(ServiceInstance instance) {
Map<String, String> metadata = instance.getMetadata();
String revision = metadata.get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME);
if (revision == null) {
revision = RevisionResolver.getEmptyRevision();
}
return revision;
}
private List<ServiceInstance> filter(Collection<ServiceInstance> serviceInstances) {
return serviceInstances.stream().filter(this::isDubboServiceInstance)
.collect(Collectors.toList());

@ -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<String, Set<String>> providers = new HashMap<>();
private final Map<String, URL> urlTemplateMap = new HashMap<>();
@ -117,7 +123,7 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan
public void init(String appName, String revision,
List<ServiceInstance> instanceList) {
List<URL> urls = getTemplateExportedURLs(url, instanceList);
List<URL> 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<URL> getTemplateExportedURLs(URL subscribedURL,
private List<URL> getTemplateExportedURLs(URL subscribedURL, String revision,
List<ServiceInstance> serviceInstances) {
DubboMetadataService dubboMetadataService = getProxy(serviceInstances);
@ -233,7 +239,8 @@ public class GenearalServiceSubscribeHandler extends AbstractServiceSubscribeHan
List<URL> 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<URL> 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()))

@ -44,6 +44,7 @@ public class MetadataServiceSubscribeHandler extends AbstractServiceSubscribeHan
this.dubboMetadataUtils = dubboMetadataUtils;
}
@Override
public void doInit() {
logger.debug("Subscription app {} MetadataService handler init", appName);
List<ServiceInstance> serviceInstances = registry.getServiceInstances(appName);

@ -78,6 +78,9 @@ public class DubboGenericServiceFactory {
String interfaceName = serviceClass.getName();
ReferenceBean<GenericService> referenceBean = build(interfaceName, version,
serviceName, emptyMap());
if (DubboMetadataService.class == serviceClass) {
referenceBean.setRouter("-default,revisionRouter");
}
return referenceBean.get();
}

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

@ -0,0 +1,75 @@
/*
* 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 org.springframework.util.CollectionUtils;
import static com.alibaba.cloud.dubbo.metadata.RevisionResolver.SCA_REVSION_KEY;
/**
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
public class MetadataServiceRevisionRouterFactory implements RouterFactory {
@Override
public Router getRouter(URL url) {
return new AbstractRouter() {
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url,
Invocation invocation) throws RpcException {
if (CollectionUtils.isEmpty(invokers)) {
return invokers;
}
if (!DubboMetadataService.class.getName()
.equalsIgnoreCase(url.getServiceInterface())) {
return invokers;
}
String revision = invocation.getAttachment(SCA_REVSION_KEY);
if (StringUtils.isEmpty(revision)) {
return invokers;
}
List<Invoker<T>> list = new ArrayList<>(invokers.size());
for (Invoker<T> invoker : invokers) {
if (StringUtils.equals(revision,
invoker.getUrl().getParameter(SCA_REVSION_KEY))) {
list.add(invoker);
}
}
return list;
}
};
}
}

@ -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<URL> getDubboMetadataServiceURLs(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
String dubboURLsJSON = metadata.get(METADATA_SERVICE_URLS_PROPERTY_NAME);
return jsonUtils.toURLs(dubboURLsJSON);
List<URL> 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;
}
/**

Loading…
Cancel
Save