mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Compare commits
14 Commits
2.2.5.RC1
...
2.2.5.RELE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68c25bc9a7 | ||
|
|
0471b45662 | ||
|
|
ddac4efc86 | ||
|
|
6924f0c3be | ||
|
|
8542756d90 | ||
|
|
4a2f90f13e | ||
|
|
dfa7747579 | ||
|
|
4c75ef9197 | ||
|
|
62398e1bc2 | ||
|
|
5a381ad278 | ||
|
|
bf08ab3110 | ||
|
|
a81430a965 | ||
|
|
bb7afd9033 | ||
|
|
5e5e5db584 |
@@ -19,7 +19,7 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。
|
|||||||
* **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
|
* **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
|
||||||
* **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。
|
* **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。
|
||||||
* **消息驱动能力**:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。
|
* **消息驱动能力**:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。
|
||||||
* **分布式事务**:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。。
|
* **分布式事务**:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。
|
||||||
* **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
* **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
||||||
* **分布式任务调度**:提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Worker(schedulerx-client)上执行。
|
* **分布式任务调度**:提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Worker(schedulerx-client)上执行。
|
||||||
* **阿里云短信服务**:覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。
|
* **阿里云短信服务**:覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Project revision -->
|
<!-- Project revision -->
|
||||||
<revision>2.2.4.RELEASE</revision>
|
<revision>2.2.5.RC2</revision>
|
||||||
|
|
||||||
<!-- Dependency Versions -->
|
<!-- Dependency Versions -->
|
||||||
<spring-cloud-commons.version>2.2.5.RELEASE</spring-cloud-commons.version>
|
<spring-cloud-commons.version>2.2.5.RELEASE</spring-cloud-commons.version>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<description>Spring Cloud Alibaba Dependencies</description>
|
<description>Spring Cloud Alibaba Dependencies</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.2.4.RELEASE</revision>
|
<revision>2.2.5.RC2</revision>
|
||||||
<sentinel.version>1.8.0</sentinel.version>
|
<sentinel.version>1.8.0</sentinel.version>
|
||||||
<seata.version>1.3.0</seata.version>
|
<seata.version>1.3.0</seata.version>
|
||||||
<nacos.client.version>1.4.1</nacos.client.version>
|
<nacos.client.version>1.4.1</nacos.client.version>
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ public class RocketMQConsumerApplication {
|
|||||||
while (true) {
|
while (true) {
|
||||||
mySink.input5().poll(m -> {
|
mySink.input5().poll(m -> {
|
||||||
String payload = (String) m.getPayload();
|
String payload = (String) m.getPayload();
|
||||||
if(payload.contains("0")){
|
if (payload.contains("0")) {
|
||||||
throw new IllegalArgumentException("111111111111111111111111111111111111111111");
|
throw new IllegalArgumentException(
|
||||||
|
"111111111111111111111111111111111111111111");
|
||||||
}
|
}
|
||||||
System.out.println("pull msg: " + payload);
|
System.out.println("pull msg: " + payload);
|
||||||
}, new ParameterizedTypeReference<String>() {
|
}, new ParameterizedTypeReference<String>() {
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import org.springframework.core.env.PropertySource;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.DOT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nacos-specific loader, If need to support other methods of parsing,you need to do the
|
* Nacos-specific loader, If need to support other methods of parsing,you need to do the
|
||||||
* following steps:
|
* following steps:
|
||||||
@@ -47,6 +45,11 @@ import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.DOT;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractPropertySourceLoader implements PropertySourceLoader {
|
public abstract class AbstractPropertySourceLoader implements PropertySourceLoader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* symbol: dot.
|
||||||
|
*/
|
||||||
|
static final String DOT = ".";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevent interference with other loaders.Nacos-specific loader, unless the reload
|
* Prevent interference with other loaders.Nacos-specific loader, unless the reload
|
||||||
* changes it.
|
* changes it.
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.utils.NacosConfigUtils;
|
||||||
|
|
||||||
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
||||||
|
import org.springframework.boot.env.PropertiesPropertySourceLoader;
|
||||||
import org.springframework.boot.env.PropertySourceLoader;
|
import org.springframework.boot.env.PropertySourceLoader;
|
||||||
import org.springframework.core.env.EnumerablePropertySource;
|
import org.springframework.core.env.EnumerablePropertySource;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
@@ -33,25 +36,17 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import static com.alibaba.cloud.nacos.parser.AbstractPropertySourceLoader.DOT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zkz
|
* @author zkz
|
||||||
*/
|
*/
|
||||||
public final class NacosDataParserHandler {
|
public final class NacosDataParserHandler {
|
||||||
|
|
||||||
/**
|
|
||||||
* symbol: dot.
|
|
||||||
*/
|
|
||||||
public static final String DOT = ".";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constant.
|
|
||||||
*/
|
|
||||||
public static final String VALUE = "value";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default extension.
|
* default extension.
|
||||||
*/
|
*/
|
||||||
public static final String DEFAULT_EXTENSION = "properties";
|
private static final String DEFAULT_EXTENSION = "properties";
|
||||||
|
|
||||||
private static List<PropertySourceLoader> propertySourceLoaders;
|
private static List<PropertySourceLoader> propertySourceLoaders;
|
||||||
|
|
||||||
@@ -80,8 +75,18 @@ public final class NacosDataParserHandler {
|
|||||||
if (!canLoadFileExtension(propertySourceLoader, extension)) {
|
if (!canLoadFileExtension(propertySourceLoader, extension)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
NacosByteArrayResource nacosByteArrayResource = new NacosByteArrayResource(
|
NacosByteArrayResource nacosByteArrayResource;
|
||||||
configValue.getBytes(), configName);
|
if (propertySourceLoader instanceof PropertiesPropertySourceLoader) {
|
||||||
|
// PropertiesPropertySourceLoader internal is to use the ISO_8859_1,
|
||||||
|
// the Chinese will be garbled, needs to transform into unicode.
|
||||||
|
nacosByteArrayResource = new NacosByteArrayResource(
|
||||||
|
NacosConfigUtils.selectiveConvertUnicode(configValue).getBytes(),
|
||||||
|
configName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nacosByteArrayResource = new NacosByteArrayResource(
|
||||||
|
configValue.getBytes(), configName);
|
||||||
|
}
|
||||||
nacosByteArrayResource.setFilename(getFileName(configName, extension));
|
nacosByteArrayResource.setFilename(getFileName(configName, extension));
|
||||||
List<PropertySource<?>> propertySourceList = propertySourceLoader
|
List<PropertySource<?>> propertySourceList = propertySourceLoader
|
||||||
.load(configName, nacosByteArrayResource);
|
.load(configName, nacosByteArrayResource);
|
||||||
|
|||||||
@@ -28,14 +28,16 @@ import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
|||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.DOT;
|
|
||||||
import static com.alibaba.cloud.nacos.parser.NacosDataParserHandler.VALUE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zkz
|
* @author zkz
|
||||||
*/
|
*/
|
||||||
public class NacosJsonPropertySourceLoader extends AbstractPropertySourceLoader {
|
public class NacosJsonPropertySourceLoader extends AbstractPropertySourceLoader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constant.
|
||||||
|
*/
|
||||||
|
private static final String VALUE = "value";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the file extensions that the loader supports (excluding the '.').
|
* Returns the file extensions that the loader supports (excluding the '.').
|
||||||
* @return the file extensions
|
* @return the file extensions
|
||||||
|
|||||||
@@ -127,8 +127,7 @@ public class NacosXmlPropertySourceLoader extends AbstractPropertySourceLoader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = StringUtils.isEmpty(parentKey) ? name
|
String key = StringUtils.isEmpty(parentKey) ? name : parentKey + DOT + name;
|
||||||
: parentKey + NacosDataParserHandler.DOT + name;
|
|
||||||
NamedNodeMap nodeMap = node.getAttributes();
|
NamedNodeMap nodeMap = node.getAttributes();
|
||||||
parseNodeAttr(nodeMap, map, key);
|
parseNodeAttr(nodeMap, map, key);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE && node.hasChildNodes()) {
|
if (node.getNodeType() == Node.ELEMENT_NODE && node.hasChildNodes()) {
|
||||||
@@ -159,8 +158,8 @@ public class NacosXmlPropertySourceLoader extends AbstractPropertySourceLoader
|
|||||||
if (StringUtils.isEmpty(node.getNodeValue())) {
|
if (StringUtils.isEmpty(node.getNodeValue())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
map.put(String.join(NacosDataParserHandler.DOT, parentKey,
|
map.put(String.join(DOT, parentKey, node.getNodeName()),
|
||||||
node.getNodeName()), node.getNodeValue());
|
node.getNodeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.nacos.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zkzlx
|
||||||
|
*/
|
||||||
|
public final class NacosConfigUtils {
|
||||||
|
|
||||||
|
private NacosConfigUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Chinese characters to Unicode.
|
||||||
|
* @param configValue value of config
|
||||||
|
* @return new string
|
||||||
|
*/
|
||||||
|
public static String selectiveConvertUnicode(String configValue) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
char[] chars = configValue.toCharArray();
|
||||||
|
for (char aChar : chars) {
|
||||||
|
if (isBaseLetter(aChar)) {
|
||||||
|
sb.append(aChar);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sb.append(String.format("\\u%04x", (int) aChar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* char is base latin or whitespace?
|
||||||
|
* @param ch a character
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
public static boolean isBaseLetter(char ch) {
|
||||||
|
Character.UnicodeBlock ub = Character.UnicodeBlock.of(ch);
|
||||||
|
return ub == Character.UnicodeBlock.BASIC_LATIN || Character.isWhitespace(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* char is chinese?
|
||||||
|
* @param c a character
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
public static boolean isChinese(char c) {
|
||||||
|
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
|
||||||
|
return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|
||||||
|
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|
||||||
|
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|
||||||
|
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|
||||||
|
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|
||||||
|
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
|||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
import com.alibaba.cloud.nacos.NacosServiceManager;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -66,6 +67,11 @@ public class NacosDiscoveryEndpoint {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
subscribe = namingService.getSubscribeServices();
|
subscribe = namingService.getSubscribeServices();
|
||||||
|
for (ServiceInfo serviceInfo : subscribe) {
|
||||||
|
List<Instance> instances = namingService.getAllInstances(
|
||||||
|
serviceInfo.getName(), serviceInfo.getGroupName());
|
||||||
|
serviceInfo.setHosts(instances);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.error("get subscribe services from nacos fail,", e);
|
log.error("get subscribe services from nacos fail,", e);
|
||||||
|
|||||||
@@ -16,10 +16,11 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.dubbo.actuate;
|
package com.alibaba.cloud.dubbo.actuate;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.dubbo.actuate.endpoint.DubboDiscoveryEndpoint;
|
||||||
|
import com.alibaba.cloud.dubbo.actuate.endpoint.DubboExportedURLsEndpoint;
|
||||||
import com.alibaba.cloud.dubbo.actuate.endpoint.DubboRestMetadataEndpoint;
|
import com.alibaba.cloud.dubbo.actuate.endpoint.DubboRestMetadataEndpoint;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||||
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -34,7 +35,7 @@ import org.springframework.context.annotation.PropertySource;
|
|||||||
@ConditionalOnClass(
|
@ConditionalOnClass(
|
||||||
name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint")
|
name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint")
|
||||||
@PropertySource("classpath:/META-INF/dubbo/default/actuator-endpoints.properties")
|
@PropertySource("classpath:/META-INF/dubbo/default/actuator-endpoints.properties")
|
||||||
@ManagementContextConfiguration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class DubboMetadataEndpointAutoConfiguration {
|
public class DubboMetadataEndpointAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -44,4 +45,19 @@ public class DubboMetadataEndpointAutoConfiguration {
|
|||||||
return new DubboRestMetadataEndpoint();
|
return new DubboRestMetadataEndpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnAvailableEndpoint
|
||||||
|
public DubboDiscoveryEndpoint dubboDiscoveryEndpoint() {
|
||||||
|
|
||||||
|
return new DubboDiscoveryEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnAvailableEndpoint
|
||||||
|
public DubboExportedURLsEndpoint dubboServiceMetadataEndpoint() {
|
||||||
|
return new DubboExportedURLsEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.dubbo.registry.DubboCloudRegistry;
|
||||||
|
import com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory;
|
||||||
|
import org.apache.dubbo.common.URL;
|
||||||
|
import org.apache.dubbo.registry.NotifyListener;
|
||||||
|
import org.apache.dubbo.registry.integration.RegistryDirectory;
|
||||||
|
import org.apache.dubbo.rpc.Invoker;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
|
|
||||||
|
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||||
|
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dubbo Registry Directory Metadata {@link DubboCloudRegistry}.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">Theonefx</a>
|
||||||
|
*/
|
||||||
|
@Endpoint(id = "dubboRegistryDirectory")
|
||||||
|
public class DubboDiscoveryEndpoint {
|
||||||
|
|
||||||
|
@ReadOperation(produces = APPLICATION_JSON_VALUE)
|
||||||
|
public Object get() {
|
||||||
|
DubboCloudRegistry registry = (DubboCloudRegistry) SpringCloudRegistryFactory
|
||||||
|
.getRegistries().stream().filter(o -> o instanceof DubboCloudRegistry)
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (registry == null) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<URL, Set<NotifyListener>> subscribeMap = registry.getSubscribed();
|
||||||
|
|
||||||
|
Map<String, List<Map<String, Object>>> result = new HashMap<>();
|
||||||
|
subscribeMap.forEach((url, listeners) -> {
|
||||||
|
String side = url.getParameter(SIDE_KEY);
|
||||||
|
if (!CONSUMER_SIDE.equals(side)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> pairs = result.computeIfAbsent(url.getServiceKey(),
|
||||||
|
o -> new ArrayList<>());
|
||||||
|
|
||||||
|
Map<String, Object> pair = new HashMap<>();
|
||||||
|
List<String> invokerServices = new ArrayList<>();
|
||||||
|
for (NotifyListener listener : listeners) {
|
||||||
|
if (!(listener instanceof RegistryDirectory)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RegistryDirectory<?> directory = (RegistryDirectory<?>) listener;
|
||||||
|
List<? extends Invoker<?>> invokers = directory.getAllInvokers();
|
||||||
|
if (invokers == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
invokerServices.addAll(invokers.stream().map(Invoker::getUrl)
|
||||||
|
.map(URL::toServiceString).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
pair.put("invokers", invokerServices);
|
||||||
|
pair.put("subscribeUrl", url.toMap());
|
||||||
|
|
||||||
|
pairs.add(pair);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.actuate.endpoint;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.dubbo.service.DubboMetadataService;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
|
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dubbo exported URLs.
|
||||||
|
* {@link org.springframework.boot.actuate.endpoint.annotation.Endpoint}.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">Theonefx</a>
|
||||||
|
*/
|
||||||
|
@Endpoint(id = "dubboExportedURLs")
|
||||||
|
public class DubboExportedURLsEndpoint {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DubboMetadataService dubboMetadataService;
|
||||||
|
|
||||||
|
@ReadOperation(produces = APPLICATION_JSON_UTF8_VALUE)
|
||||||
|
public Object get() {
|
||||||
|
return dubboMetadataService.getAllExportedURLs();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -44,6 +44,8 @@ import org.springframework.cloud.client.ServiceInstance;
|
|||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
@@ -184,16 +186,30 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
subscribeURLs(url, getServices(url), listener);
|
subscribeURLs(url, getServices(url), listener);
|
||||||
|
|
||||||
// Async subscription
|
// Async subscription
|
||||||
registerServiceInstancesChangedListener(url, event -> {
|
registerServiceInstancesChangedListener(url,
|
||||||
|
|
||||||
Set<String> serviceNames = getServices(url);
|
new ApplicationListener<ServiceInstancesChangedEvent>() {
|
||||||
|
|
||||||
String serviceName = event.getServiceName();
|
private final URL url2subscribe = url;
|
||||||
|
|
||||||
if (serviceNames.contains(serviceName)) {
|
@Override
|
||||||
subscribeURLs(url, serviceNames, listener);
|
@Order
|
||||||
}
|
public void onApplicationEvent(ServiceInstancesChangedEvent event) {
|
||||||
});
|
Set<String> serviceNames = getServices(url);
|
||||||
|
|
||||||
|
String serviceName = event.getServiceName();
|
||||||
|
|
||||||
|
if (serviceNames.contains(serviceName)) {
|
||||||
|
subscribeURLs(url, serviceNames, listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ServiceInstancesChangedEventListener:"
|
||||||
|
+ url.getServiceKey();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void subscribeURLs(URL url, Set<String> serviceNames,
|
private void subscribeURLs(URL url, Set<String> serviceNames,
|
||||||
@@ -375,12 +391,12 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
// Add the EMPTY_PROTOCOL URL
|
// Add the EMPTY_PROTOCOL URL
|
||||||
subscribedURLs.add(emptyURL(url));
|
subscribedURLs.add(emptyURL(url));
|
||||||
|
|
||||||
if (isDubboMetadataServiceURL(url)) {
|
// if (isDubboMetadataServiceURL(url)) {
|
||||||
// if meta service change, and serviceInstances is zero, will clean up
|
// if meta service change, and serviceInstances is zero, will clean up
|
||||||
// information about this client
|
// information about this client
|
||||||
String serviceName = url.getParameter(GROUP_KEY);
|
// String serviceName = url.getParameter(GROUP_KEY);
|
||||||
repository.removeMetadataAndInitializedService(serviceName, url);
|
// repository.removeMetadataAndInitializedService(serviceName, url);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@@ -415,7 +431,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String generateId(URL url) {
|
private String generateId(URL url) {
|
||||||
return url.getServiceKey();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL emptyURL(URL url) {
|
private URL emptyURL(URL url) {
|
||||||
@@ -450,16 +466,30 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
|
|
||||||
// Sync subscription
|
// Sync subscription
|
||||||
if (containsProviderCategory(subscribedURL)) {
|
if (containsProviderCategory(subscribedURL)) {
|
||||||
registerServiceInstancesChangedListener(subscribedURL, event -> {
|
registerServiceInstancesChangedListener(subscribedURL,
|
||||||
|
new ApplicationListener<ServiceInstancesChangedEvent>() {
|
||||||
|
|
||||||
String sourceServiceName = event.getServiceName();
|
private final URL url2subscribe = subscribedURL;
|
||||||
String serviceName = getServiceName(subscribedURL);
|
|
||||||
|
|
||||||
if (Objects.equals(sourceServiceName, serviceName)) {
|
@Override
|
||||||
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
|
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
||||||
sourceServiceName);
|
public void onApplicationEvent(
|
||||||
}
|
ServiceInstancesChangedEvent event) {
|
||||||
});
|
String sourceServiceName = event.getServiceName();
|
||||||
|
String serviceName = getServiceName(subscribedURL);
|
||||||
|
|
||||||
|
if (Objects.equals(sourceServiceName, serviceName)) {
|
||||||
|
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
|
||||||
|
sourceServiceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ServiceInstancesChangedEventListener:"
|
||||||
|
+ subscribedURL.getServiceKey();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
|
|||||||
*/
|
*/
|
||||||
public DubboMetadataService getProxy(List<ServiceInstance> serviceInstances) {
|
public DubboMetadataService getProxy(List<ServiceInstance> serviceInstances) {
|
||||||
|
|
||||||
DubboMetadataService dubboMetadataService = null;
|
|
||||||
|
|
||||||
// attempt to get the proxy of DubboMetadataService in maximum times
|
// attempt to get the proxy of DubboMetadataService in maximum times
|
||||||
int attempts = serviceInstances.size();
|
int attempts = serviceInstances.size();
|
||||||
|
|
||||||
@@ -98,7 +96,8 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
|
|||||||
serviceInstance.get());
|
serviceInstance.get());
|
||||||
|
|
||||||
for (URL dubboMetadataServiceURL : dubboMetadataServiceURLs) {
|
for (URL dubboMetadataServiceURL : dubboMetadataServiceURLs) {
|
||||||
dubboMetadataService = createProxyIfAbsent(dubboMetadataServiceURL);
|
DubboMetadataService dubboMetadataService = createProxyIfAbsent(
|
||||||
|
dubboMetadataServiceURL);
|
||||||
if (dubboMetadataService != null) {
|
if (dubboMetadataService != null) {
|
||||||
return dubboMetadataService;
|
return dubboMetadataService;
|
||||||
}
|
}
|
||||||
@@ -106,7 +105,7 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dubboMetadataService;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration,
|
|||||||
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationNonWebApplicationAutoConfiguration,\
|
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationNonWebApplicationAutoConfiguration,\
|
||||||
com.alibaba.cloud.dubbo.autoconfigure.DubboLoadBalancedRestTemplateAutoConfiguration,\
|
com.alibaba.cloud.dubbo.autoconfigure.DubboLoadBalancedRestTemplateAutoConfiguration,\
|
||||||
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceAutoConfiguration,\
|
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceAutoConfiguration,\
|
||||||
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration
|
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
|
|
||||||
com.alibaba.cloud.dubbo.actuate.DubboMetadataEndpointAutoConfiguration
|
com.alibaba.cloud.dubbo.actuate.DubboMetadataEndpointAutoConfiguration
|
||||||
org.springframework.context.ApplicationContextInitializer=\
|
org.springframework.context.ApplicationContextInitializer=\
|
||||||
com.alibaba.cloud.dubbo.context.DubboServiceRegistrationApplicationContextInitializer
|
com.alibaba.cloud.dubbo.context.DubboServiceRegistrationApplicationContextInitializer
|
||||||
|
|||||||
Reference in New Issue
Block a user