mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
sync code from master branch
This commit is contained in:
parent
b120c13033
commit
c05d74c095
2
pom.xml
2
pom.xml
@ -98,7 +98,7 @@
|
|||||||
<module>spring-cloud-alibaba-fescar</module>
|
<module>spring-cloud-alibaba-fescar</module>
|
||||||
<module>spring-cloud-stream-binder-rocketmq</module>
|
<module>spring-cloud-stream-binder-rocketmq</module>
|
||||||
<module>spring-cloud-alibaba-nacos-config-server</module>
|
<module>spring-cloud-alibaba-nacos-config-server</module>
|
||||||
<!--<module>spring-cloud-alibaba-dubbo</module>-->
|
<module>spring-cloud-alibaba-dubbo</module>
|
||||||
<module>spring-cloud-alicloud-context</module>
|
<module>spring-cloud-alicloud-context</module>
|
||||||
<module>spring-cloud-alibaba-examples</module>
|
<module>spring-cloud-alibaba-examples</module>
|
||||||
<module>spring-cloud-alibaba-test</module>
|
<module>spring-cloud-alibaba-test</module>
|
||||||
|
@ -179,7 +179,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.dubbo</groupId>
|
<groupId>org.apache.dubbo</groupId>
|
||||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||||
<version>${dubbo-spring-boot.version}</version>
|
<version>${dubbo.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Netty -->
|
<!-- Netty -->
|
||||||
|
@ -16,12 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.cloud.alibaba.dubbo.autoconfigure;
|
package org.springframework.cloud.alibaba.dubbo.autoconfigure;
|
||||||
|
|
||||||
import org.apache.dubbo.common.utils.Assert;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.apache.dubbo.config.spring.util.PropertySourcesUtils;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
|
||||||
import org.springframework.cloud.alibaba.dubbo.env.DubboCloudProperties;
|
import org.springframework.cloud.alibaba.dubbo.env.DubboCloudProperties;
|
||||||
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory;
|
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory;
|
||||||
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
|
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
|
||||||
@ -33,17 +30,8 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.env.AbstractEnvironment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
|
||||||
import org.springframework.core.env.MapPropertySource;
|
|
||||||
import org.springframework.core.env.MutablePropertySources;
|
|
||||||
import org.springframework.core.env.PropertyResolver;
|
import org.springframework.core.env.PropertyResolver;
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.apache.dubbo.spring.boot.util.DubboUtils.BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME;
|
|
||||||
import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SCAN_PREFIX;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring Boot Auto-Configuration class for Dubbo Service
|
* Spring Boot Auto-Configuration class for Dubbo Service
|
||||||
@ -72,80 +60,14 @@ public class DubboServiceAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bugfix code for an issue : https://github.com/apache/incubator-dubbo-spring-boot-project/issues/459
|
* Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired}
|
||||||
*
|
*
|
||||||
* @param environment {@link ConfigurableEnvironment}
|
* @param environment {@link Environment}
|
||||||
* @return a Bean of {@link PropertyResolver}
|
* @return alias bean for {@link Environment}
|
||||||
*/
|
*/
|
||||||
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
|
public PropertyResolver primaryPropertyResolver(Environment environment) {
|
||||||
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
|
return environment;
|
||||||
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
|
|
||||||
@Override
|
|
||||||
protected void customizePropertySources(MutablePropertySources propertySources) {
|
|
||||||
Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX);
|
|
||||||
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ConfigurationPropertySources.attach(propertyResolver);
|
|
||||||
return new DelegatingPropertyResolver(propertyResolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static class DelegatingPropertyResolver implements PropertyResolver {
|
|
||||||
|
|
||||||
private final PropertyResolver delegate;
|
|
||||||
|
|
||||||
DelegatingPropertyResolver(PropertyResolver delegate) {
|
|
||||||
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsProperty(String key) {
|
|
||||||
return delegate.containsProperty(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String getProperty(String key) {
|
|
||||||
return delegate.getProperty(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProperty(String key, String defaultValue) {
|
|
||||||
return delegate.getProperty(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public <T> T getProperty(String key, Class<T> targetType) {
|
|
||||||
return delegate.getProperty(key, targetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
|
|
||||||
return delegate.getProperty(key, targetType, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRequiredProperty(String key) throws IllegalStateException {
|
|
||||||
return delegate.getRequiredProperty(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
|
|
||||||
return delegate.getRequiredProperty(key, targetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String resolvePlaceholders(String text) {
|
|
||||||
return delegate.resolvePlaceholders(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
|
|
||||||
return delegate.resolveRequiredPlaceholders(text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,6 @@ package org.springframework.cloud.alibaba.dubbo.registry;
|
|||||||
|
|
||||||
import org.apache.dubbo.common.Constants;
|
import org.apache.dubbo.common.Constants;
|
||||||
import org.apache.dubbo.common.URL;
|
import org.apache.dubbo.common.URL;
|
||||||
import org.apache.dubbo.common.utils.UrlUtils;
|
|
||||||
import org.apache.dubbo.registry.NotifyListener;
|
import org.apache.dubbo.registry.NotifyListener;
|
||||||
import org.apache.dubbo.registry.RegistryFactory;
|
import org.apache.dubbo.registry.RegistryFactory;
|
||||||
import org.apache.dubbo.registry.support.FailbackRegistry;
|
import org.apache.dubbo.registry.support.FailbackRegistry;
|
||||||
@ -29,20 +28,21 @@ import org.springframework.cloud.client.ServiceInstance;
|
|||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singleton;
|
import static java.util.Collections.singleton;
|
||||||
import static org.apache.dubbo.common.Constants.PROVIDER_SIDE;
|
import static org.apache.dubbo.common.Constants.PROVIDER_SIDE;
|
||||||
import static org.apache.dubbo.common.Constants.SIDE_KEY;
|
import static org.apache.dubbo.common.Constants.SIDE_KEY;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
|
import static org.springframework.util.StringUtils.hasText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Dubbo {@link RegistryFactory} uses Spring Cloud Service Registration abstraction, whose protocol is "spring-cloud"
|
* Abstract Dubbo {@link RegistryFactory} uses Spring Cloud Service Registration abstraction, whose protocol is "spring-cloud"
|
||||||
@ -144,13 +144,8 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterServiceNames(Collection<String> serviceNames) {
|
private Set<String> filterServiceNames(Collection<String> serviceNames) {
|
||||||
filter(serviceNames, new Filter<String>() {
|
return new LinkedHashSet<>(filter(serviceNames, this::supports));
|
||||||
@Override
|
|
||||||
public boolean accept(String serviceName) {
|
|
||||||
return supports(serviceName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean supports(String serviceName);
|
protected abstract boolean supports(String serviceName);
|
||||||
@ -185,8 +180,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
*/
|
*/
|
||||||
protected Set<String> getServiceNamesForOps(URL url) {
|
protected Set<String> getServiceNamesForOps(URL url) {
|
||||||
Set<String> serviceNames = getAllServiceNames();
|
Set<String> serviceNames = getAllServiceNames();
|
||||||
filterServiceNames(serviceNames);
|
return filterServiceNames(serviceNames);
|
||||||
return serviceNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getServiceName(URL url);
|
protected abstract String getServiceName(URL url);
|
||||||
@ -206,7 +200,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected List<ServiceInstance> getServiceInstances(String serviceName) {
|
protected List<ServiceInstance> getServiceInstances(String serviceName) {
|
||||||
return discoveryClient.getInstances(serviceName);
|
return hasText(serviceName) ? discoveryClient.getInstances(serviceName) : emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void subscribe(final URL url, final NotifyListener listener, final Collection<String> serviceNames) {
|
private void subscribe(final URL url, final NotifyListener listener, final Collection<String> serviceNames) {
|
||||||
@ -227,67 +221,9 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
*/
|
*/
|
||||||
protected abstract void notifySubscriber(URL url, NotifyListener listener, List<ServiceInstance> serviceInstances);
|
protected abstract void notifySubscriber(URL url, NotifyListener listener, List<ServiceInstance> serviceInstances);
|
||||||
|
|
||||||
protected void filterHealthyInstances(Collection<ServiceInstance> instances) {
|
protected <T> Collection<T> filter(Collection<T> collection, Predicate<T> filter) {
|
||||||
filter(instances, new Filter<ServiceInstance>() {
|
return collection.stream()
|
||||||
@Override
|
.filter(filter)
|
||||||
public boolean accept(ServiceInstance data) {
|
.collect(Collectors.toList());
|
||||||
// TODO check the details of status
|
|
||||||
// return serviceRegistry.getStatus(new DubboRegistration(data)) != null;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<URL> buildURLs(URL consumerURL, Collection<ServiceInstance> serviceInstances) {
|
|
||||||
if (serviceInstances.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<URL> urls = new LinkedList<URL>();
|
|
||||||
for (ServiceInstance serviceInstance : serviceInstances) {
|
|
||||||
URL url = buildURL(serviceInstance);
|
|
||||||
if (UrlUtils.isMatch(consumerURL, url)) {
|
|
||||||
urls.add(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private URL buildURL(ServiceInstance serviceInstance) {
|
|
||||||
URL url = new URL(serviceInstance.getMetadata().get(Constants.PROTOCOL_KEY),
|
|
||||||
serviceInstance.getHost(),
|
|
||||||
serviceInstance.getPort(),
|
|
||||||
serviceInstance.getMetadata());
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> void filter(Collection<T> collection, Filter<T> filter) {
|
|
||||||
Iterator<T> iterator = collection.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
T data = iterator.next();
|
|
||||||
if (!filter.accept(data)) { // remove if not accept
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> T[] of(T... values) {
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A filter
|
|
||||||
*/
|
|
||||||
public interface Filter<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether or not the specified data should be accepted.
|
|
||||||
*
|
|
||||||
* @param data The data to be tested
|
|
||||||
* @return <code>true</code> if and only if <code>data</code>
|
|
||||||
* should be accepted
|
|
||||||
*/
|
|
||||||
boolean accept(T data);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class NacosDiscoveryProperties {
|
|||||||
/**
|
/**
|
||||||
* watch delay,duration to pull new service from nacos server.
|
* watch delay,duration to pull new service from nacos server.
|
||||||
*/
|
*/
|
||||||
private long watchDelay = 5000;
|
private long watchDelay = 30000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos naming log file name
|
* nacos naming log file name
|
||||||
|
@ -19,6 +19,6 @@
|
|||||||
<module>spring-cloud-starter-alibaba-fescar</module>
|
<module>spring-cloud-starter-alibaba-fescar</module>
|
||||||
<module>spring-cloud-starter-stream-rocketmq</module>
|
<module>spring-cloud-starter-stream-rocketmq</module>
|
||||||
<module>spring-cloud-starter-bus-rocketmq</module>
|
<module>spring-cloud-starter-bus-rocketmq</module>
|
||||||
<!--<module>spring-cloud-starter-dubbo</module>-->
|
<module>spring-cloud-starter-dubbo</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
Loading…
x
Reference in New Issue
Block a user