1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

merge 2.2.5.RELEASE

This commit is contained in:
theonefx 2021-02-01 14:44:04 +08:00
commit c9d27f1e09
11 changed files with 236 additions and 38 deletions

View File

@ -19,7 +19,7 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。
* **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
* **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。
* **消息驱动能力**:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。
* **分布式事务**:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。
* **分布式事务**:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。
* **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。
* **分布式任务调度**:提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Workerschedulerx-client上执行。
* **阿里云短信服务**:覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。

View File

@ -71,7 +71,7 @@ These artifacts are available from Maven Central and Spring Release repository v
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.4.RELEASE</version>
<version>2.2.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -75,7 +75,8 @@ public class RocketMQConsumerApplication {
mySink.input5().poll(m -> {
String payload = (String) m.getPayload();
if (payload.contains("0")) {
throw new IllegalArgumentException("111111111111111111111111111111111111111111");
throw new IllegalArgumentException(
"111111111111111111111111111111111111111111");
}
System.out.println("pull msg: " + payload);
}, new ParameterizedTypeReference<String>() {

View File

@ -33,16 +33,26 @@ public final class NacosConfigUtils {
StringBuilder sb = new StringBuilder();
char[] chars = configValue.toCharArray();
for (char aChar : chars) {
if (isChinese(aChar)) {
sb.append("\\u").append(Integer.toHexString(aChar));
if (isBaseLetter(aChar)) {
sb.append(aChar);
}
else {
sb.append(aChar);
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

View File

@ -24,6 +24,7 @@ import java.util.Map;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -66,6 +67,11 @@ public class NacosDiscoveryEndpoint {
try {
subscribe = namingService.getSubscribeServices();
for (ServiceInfo serviceInfo : subscribe) {
List<Instance> instances = namingService.getAllInstances(
serviceInfo.getName(), serviceInfo.getGroupName());
serviceInfo.setHosts(instances);
}
}
catch (Exception e) {
log.error("get subscribe services from nacos fail,", e);

View File

@ -16,10 +16,11 @@
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 org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
@ -33,7 +34,7 @@ import org.springframework.context.annotation.PropertySource;
*/
@ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint")
@PropertySource("classpath:/META-INF/dubbo/default/actuator-endpoints.properties")
@ManagementContextConfiguration
@Configuration
public class DubboMetadataEndpointAutoConfiguration {
@Bean
@ -43,4 +44,19 @@ public class DubboMetadataEndpointAutoConfiguration {
return new DubboRestMetadataEndpoint();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public DubboDiscoveryEndpoint dubboDiscoveryEndpoint() {
return new DubboDiscoveryEndpoint();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public DubboExportedURLsEndpoint dubboServiceMetadataEndpoint() {
return new DubboExportedURLsEndpoint();
}
}

View File

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

View File

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

View File

@ -44,6 +44,8 @@ import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.util.CollectionUtils;
import static java.lang.String.format;
@ -184,8 +186,15 @@ public class DubboCloudRegistry extends FailbackRegistry {
subscribeURLs(url, getServices(url), listener);
// Async subscription
registerServiceInstancesChangedListener(url, event -> {
registerServiceInstancesChangedListener(url,
new ApplicationListener<ServiceInstancesChangedEvent>() {
private final URL url2subscribe = url;
@Override
@Order
public void onApplicationEvent(ServiceInstancesChangedEvent event) {
Set<String> serviceNames = getServices(url);
String serviceName = event.getServiceName();
@ -193,6 +202,13 @@ public class DubboCloudRegistry extends FailbackRegistry {
if (serviceNames.contains(serviceName)) {
subscribeURLs(url, serviceNames, listener);
}
}
@Override
public String toString() {
return "ServiceInstancesChangedEventListener:"
+ url.getServiceKey();
}
});
}
@ -375,12 +391,12 @@ public class DubboCloudRegistry extends FailbackRegistry {
// Add the EMPTY_PROTOCOL URL
subscribedURLs.add(emptyURL(url));
if (isDubboMetadataServiceURL(url)) {
// if (isDubboMetadataServiceURL(url)) {
// if meta service change, and serviceInstances is zero, will clean up
// information about this client
String serviceName = url.getParameter(GROUP_KEY);
repository.removeMetadataAndInitializedService(serviceName, url);
}
// String serviceName = url.getParameter(GROUP_KEY);
// repository.removeMetadataAndInitializedService(serviceName, url);
// }
}
if (logger.isDebugEnabled()) {
@ -415,7 +431,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
}
private String generateId(URL url) {
return url.getServiceKey();
return url.toString();
}
private URL emptyURL(URL url) {
@ -450,8 +466,15 @@ public class DubboCloudRegistry extends FailbackRegistry {
// Sync subscription
if (containsProviderCategory(subscribedURL)) {
registerServiceInstancesChangedListener(subscribedURL, event -> {
registerServiceInstancesChangedListener(subscribedURL,
new ApplicationListener<ServiceInstancesChangedEvent>() {
private final URL url2subscribe = subscribedURL;
@Override
@Order(Ordered.LOWEST_PRECEDENCE - 1)
public void onApplicationEvent(
ServiceInstancesChangedEvent event) {
String sourceServiceName = event.getServiceName();
String serviceName = getServiceName(subscribedURL);
@ -459,6 +482,13 @@ public class DubboCloudRegistry extends FailbackRegistry {
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
sourceServiceName);
}
}
@Override
public String toString() {
return "ServiceInstancesChangedEventListener:"
+ subscribedURL.getServiceKey();
}
});
}
}

View File

@ -84,8 +84,6 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
*/
public DubboMetadataService getProxy(List<ServiceInstance> serviceInstances) {
DubboMetadataService dubboMetadataService = null;
// attempt to get the proxy of DubboMetadataService in maximum times
int attempts = serviceInstances.size();
@ -98,7 +96,8 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
serviceInstance.get());
for (URL dubboMetadataServiceURL : dubboMetadataServiceURLs) {
dubboMetadataService = createProxyIfAbsent(dubboMetadataServiceURL);
DubboMetadataService dubboMetadataService = createProxyIfAbsent(
dubboMetadataServiceURL);
if (dubboMetadataService != null) {
return dubboMetadataService;
}
@ -106,7 +105,7 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab
}
}
return dubboMetadataService;
return null;
}
/**

View File

@ -5,8 +5,7 @@ com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration,
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationNonWebApplicationAutoConfiguration,\
com.alibaba.cloud.dubbo.autoconfigure.DubboLoadBalancedRestTemplateAutoConfiguration,\
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceAutoConfiguration,\
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration,\
com.alibaba.cloud.dubbo.actuate.DubboMetadataEndpointAutoConfiguration
org.springframework.context.ApplicationContextInitializer=\
com.alibaba.cloud.dubbo.context.DubboServiceRegistrationApplicationContextInitializer