mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
finchley dubbo sync
This commit is contained in:
parent
d97a5c13a8
commit
7914702ef9
@ -30,7 +30,7 @@
|
|||||||
<aliyun.sdk.edas.version>2.44.0</aliyun.sdk.edas.version>
|
<aliyun.sdk.edas.version>2.44.0</aliyun.sdk.edas.version>
|
||||||
<rocketmq.starter.version>2.0.2</rocketmq.starter.version>
|
<rocketmq.starter.version>2.0.2</rocketmq.starter.version>
|
||||||
<schedulerX.client.version>2.1.6</schedulerX.client.version>
|
<schedulerX.client.version>2.1.6</schedulerX.client.version>
|
||||||
<dubbo.version>2.7.1</dubbo.version>
|
<dubbo.version>2.7.3</dubbo.version>
|
||||||
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
|
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
|
||||||
<dubbo-registry-nacos.version>2.7.1</dubbo-registry-nacos.version>
|
<dubbo-registry-nacos.version>2.7.1</dubbo-registry-nacos.version>
|
||||||
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
|
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
|
||||||
@ -203,7 +203,6 @@
|
|||||||
<artifactId>sentinel-spring-webflux-adapter</artifactId>
|
<artifactId>sentinel-spring-webflux-adapter</artifactId>
|
||||||
<version>${sentinel.version}</version>
|
<version>${sentinel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.csp</groupId>
|
<groupId>com.alibaba.csp</groupId>
|
||||||
<artifactId>sentinel-api-gateway-adapter-common</artifactId>
|
<artifactId>sentinel-api-gateway-adapter-common</artifactId>
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
<name>Spring Cloud Alibaba Dubbo</name>
|
<name>Spring Cloud Alibaba Dubbo</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<dubbo.version>2.7.1</dubbo.version>
|
<dubbo.version>2.7.3</dubbo.version>
|
||||||
|
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
|
||||||
<spring-cloud-zookeeper.version>2.0.2.RELEASE</spring-cloud-zookeeper.version>
|
<spring-cloud-zookeeper.version>2.0.2.RELEASE</spring-cloud-zookeeper.version>
|
||||||
<spring-cloud-consul.version>2.0.3.RELEASE</spring-cloud-consul.version>
|
<spring-cloud-consul.version>2.0.3.RELEASE</spring-cloud-consul.version>
|
||||||
<curator.version>4.0.1</curator.version>
|
<curator.version>4.0.1</curator.version>
|
||||||
@ -178,14 +179,15 @@
|
|||||||
<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.version}</version>
|
<version>${dubbo-spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Dubbo Spring Boot Actuator -->
|
<!-- Dubbo Spring Boot Actuator (optional) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.dubbo</groupId>
|
<groupId>org.apache.dubbo</groupId>
|
||||||
<artifactId>dubbo-spring-boot-actuator</artifactId>
|
<artifactId>dubbo-spring-boot-actuator</artifactId>
|
||||||
<version>${dubbo.version}</version>
|
<version>${dubbo-spring-boot.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Netty -->
|
<!-- Netty -->
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.cloud.dubbo.annotation;
|
package com.alibaba.cloud.dubbo.annotation;
|
||||||
|
|
||||||
import static org.apache.dubbo.common.Constants.DEFAULT_RETRIES;
|
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_RETRIES;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
@ -24,7 +24,6 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.apache.dubbo.common.Constants;
|
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
import org.apache.dubbo.config.annotation.Reference;
|
||||||
import org.apache.dubbo.rpc.ExporterListener;
|
import org.apache.dubbo.rpc.ExporterListener;
|
||||||
import org.apache.dubbo.rpc.Filter;
|
import org.apache.dubbo.rpc.Filter;
|
||||||
@ -81,7 +80,6 @@ public @interface DubboTransported {
|
|||||||
* Whether to reconnect if connection is lost, if not specify, reconnect is enabled by
|
* Whether to reconnect if connection is lost, if not specify, reconnect is enabled by
|
||||||
* default, and the interval for retry connecting is 2000 ms
|
* default, and the interval for retry connecting is 2000 ms
|
||||||
*
|
*
|
||||||
* @see Constants#DEFAULT_RECONNECT_PERIOD
|
|
||||||
* @see Reference#reconnect()
|
* @see Reference#reconnect()
|
||||||
*/
|
*/
|
||||||
String reconnect() default "${dubbo.transport.reconnect:2000}";
|
String reconnect() default "${dubbo.transport.reconnect:2000}";
|
||||||
@ -97,7 +95,6 @@ public @interface DubboTransported {
|
|||||||
/**
|
/**
|
||||||
* Service invocation retry times
|
* Service invocation retry times
|
||||||
*
|
*
|
||||||
* @see Constants#DEFAULT_RETRIES
|
|
||||||
* @see Reference#retries()
|
* @see Reference#retries()
|
||||||
*/
|
*/
|
||||||
int retries() default DEFAULT_RETRIES;
|
int retries() default DEFAULT_RETRIES;
|
||||||
@ -105,7 +102,6 @@ public @interface DubboTransported {
|
|||||||
/**
|
/**
|
||||||
* Load balance strategy, legal values include: random, roundrobin, leastactive
|
* Load balance strategy, legal values include: random, roundrobin, leastactive
|
||||||
*
|
*
|
||||||
* @see Constants#DEFAULT_LOADBALANCE
|
|
||||||
* @see Reference#loadbalance()
|
* @see Reference#loadbalance()
|
||||||
*/
|
*/
|
||||||
String loadbalance() default "${dubbo.transport.loadbalance:}";
|
String loadbalance() default "${dubbo.transport.loadbalance:}";
|
||||||
|
@ -18,12 +18,15 @@ package com.alibaba.cloud.dubbo.autoconfigure;
|
|||||||
|
|
||||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_CONFIGURATION_CLASS_NAME;
|
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_CONFIGURATION_CLASS_NAME;
|
||||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_AUTO_CONFIGURATION_CLASS_NAME;
|
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_AUTO_CONFIGURATION_CLASS_NAME;
|
||||||
|
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.ADDRESS;
|
||||||
|
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.dubbo.config.RegistryConfig;
|
||||||
import org.apache.dubbo.config.spring.ServiceBean;
|
import org.apache.dubbo.config.spring.ServiceBean;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -43,10 +46,13 @@ import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServic
|
|||||||
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
|
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
|
||||||
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry;
|
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry;
|
||||||
import org.springframework.context.SmartLifecycle;
|
import org.springframework.context.SmartLifecycle;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Conditional;
|
||||||
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.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition;
|
||||||
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
||||||
import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect;
|
import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect;
|
||||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
|
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
|
||||||
@ -82,6 +88,12 @@ public class DubboServiceRegistrationAutoConfiguration {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DubboServiceMetadataRepository dubboServiceMetadataRepository;
|
private DubboServiceMetadataRepository dubboServiceMetadataRepository;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Conditional(value = { MissingSpringCloudRegistryConfigPropertyCondition.class })
|
||||||
|
public RegistryConfig defaultSpringCloudRegistryConfig() {
|
||||||
|
return new RegistryConfig(ADDRESS, PROTOCOL);
|
||||||
|
}
|
||||||
|
|
||||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||||
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
|
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
|
||||||
Registration registration = event.getSource();
|
Registration registration = event.getSource();
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You 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
|
||||||
|
*
|
||||||
|
* http://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.autoconfigure.condition;
|
||||||
|
|
||||||
|
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
||||||
|
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||||
|
import org.springframework.context.annotation.Condition;
|
||||||
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Missing {@link SpringCloudRegistry} Property {@link Condition}
|
||||||
|
*
|
||||||
|
* @see SpringCloudRegistry
|
||||||
|
* @see Condition
|
||||||
|
*/
|
||||||
|
public class MissingSpringCloudRegistryConfigPropertyCondition
|
||||||
|
extends SpringBootCondition {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||||
|
AnnotatedTypeMetadata metadata) {
|
||||||
|
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
|
||||||
|
.getEnvironment();
|
||||||
|
|
||||||
|
String protocol = environment.getProperty("dubbo.registry.protocol");
|
||||||
|
|
||||||
|
if (PROTOCOL.equals(protocol)) {
|
||||||
|
return ConditionOutcome.noMatch(
|
||||||
|
"'spring-cloud' protocol was found from 'dubbo.registry.protocol'");
|
||||||
|
}
|
||||||
|
|
||||||
|
String address = environment.getProperty("dubbo.registry.address");
|
||||||
|
|
||||||
|
if (StringUtils.startsWithIgnoreCase(address, PROTOCOL)) {
|
||||||
|
return ConditionOutcome.noMatch(
|
||||||
|
"'spring-cloud' protocol was found from 'dubbo.registry.address'");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> properties = getSubProperties(environment,
|
||||||
|
"dubbo.registries.");
|
||||||
|
|
||||||
|
boolean found = properties.entrySet().stream().anyMatch(entry -> {
|
||||||
|
String key = entry.getKey();
|
||||||
|
String value = String.valueOf(entry.getValue());
|
||||||
|
return (key.endsWith(".address") && value.startsWith(PROTOCOL))
|
||||||
|
|| (key.endsWith(".protocol") && PROTOCOL.equals(value));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return found
|
||||||
|
? ConditionOutcome.noMatch(
|
||||||
|
"'spring-cloud' protocol was found in 'dubbo.registries.*'")
|
||||||
|
: ConditionOutcome.match();
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.cloud.dubbo.env;
|
package com.alibaba.cloud.dubbo.env;
|
||||||
|
|
||||||
import static org.apache.dubbo.common.Constants.DEFAULT_PROTOCOL;
|
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL;
|
||||||
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties;
|
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.cloud.dubbo.metadata;
|
package com.alibaba.cloud.dubbo.metadata;
|
||||||
|
|
||||||
import static org.apache.dubbo.common.Constants.DEFAULT_PROTOCOL;
|
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL;
|
||||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.alibaba.cloud.dubbo.metadata.repository;
|
package com.alibaba.cloud.dubbo.metadata.repository;
|
||||||
|
|
||||||
|
import static com.alibaba.cloud.dubbo.env.DubboCloudProperties.ALL_DUBBO_SERVICES;
|
||||||
|
import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static java.lang.String.valueOf;
|
import static java.lang.String.valueOf;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
@ -23,8 +25,8 @@ import static java.util.Collections.emptySet;
|
|||||||
import static java.util.Collections.unmodifiableList;
|
import static java.util.Collections.unmodifiableList;
|
||||||
import static java.util.Collections.unmodifiableMap;
|
import static java.util.Collections.unmodifiableMap;
|
||||||
import static java.util.Collections.unmodifiableSet;
|
import static java.util.Collections.unmodifiableSet;
|
||||||
import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.VERSION_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||||
import static org.springframework.util.StringUtils.hasText;
|
import static org.springframework.util.StringUtils.hasText;
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -47,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.client.ServiceInstance;
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.cloud.commons.util.InetUtils;
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -54,7 +58,6 @@ import org.springframework.util.LinkedMultiValueMap;
|
|||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
import com.alibaba.cloud.dubbo.env.DubboCloudProperties;
|
import com.alibaba.cloud.dubbo.env.DubboCloudProperties;
|
||||||
import com.alibaba.cloud.dubbo.http.DefaultHttpRequest;
|
|
||||||
import com.alibaba.cloud.dubbo.http.matcher.RequestMetadataMatcher;
|
import com.alibaba.cloud.dubbo.http.matcher.RequestMetadataMatcher;
|
||||||
import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata;
|
import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata;
|
||||||
import com.alibaba.cloud.dubbo.metadata.RequestMetadata;
|
import com.alibaba.cloud.dubbo.metadata.RequestMetadata;
|
||||||
@ -157,6 +160,9 @@ public class DubboServiceMetadataRepository {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private JSONUtils jsonUtils;
|
private JSONUtils jsonUtils;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InetUtils inetUtils;
|
||||||
|
|
||||||
@Value("${spring.application.name}")
|
@Value("${spring.application.name}")
|
||||||
private String currentApplicationName;
|
private String currentApplicationName;
|
||||||
|
|
||||||
@ -284,14 +290,27 @@ public class DubboServiceMetadataRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void exportURL(URL url) {
|
public void exportURL(URL url) {
|
||||||
this.allExportedURLs.add(url.getServiceKey(), url);
|
URL actualURL = url;
|
||||||
|
InetUtils.HostInfo hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
|
||||||
|
String ipAddress = hostInfo.getIpAddress();
|
||||||
|
// To use InetUtils to set IP if they are different
|
||||||
|
// issue :
|
||||||
|
// https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/589
|
||||||
|
if (!Objects.equals(url.getHost(), ipAddress)) {
|
||||||
|
actualURL = url.setHost(ipAddress);
|
||||||
|
}
|
||||||
|
this.allExportedURLs.add(actualURL.getServiceKey(), actualURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unexportURL(URL url) {
|
public void unexportURL(URL url) {
|
||||||
String key = url.getServiceKey();
|
String key = url.getServiceKey();
|
||||||
|
// NPE issue :
|
||||||
|
// https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/591
|
||||||
List<URL> urls = allExportedURLs.get(key);
|
List<URL> urls = allExportedURLs.get(key);
|
||||||
urls.remove(url);
|
if (!isEmpty(urls)) {
|
||||||
this.allExportedURLs.addAll(key, urls);
|
urls.remove(url);
|
||||||
|
allExportedURLs.addAll(key, urls);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -413,8 +432,7 @@ public class DubboServiceMetadataRepository {
|
|||||||
object = map.get(matcher);
|
object = map.get(matcher);
|
||||||
if (object == null) { // Can't match exactly
|
if (object == null) { // Can't match exactly
|
||||||
// Require to match one by one
|
// Require to match one by one
|
||||||
HttpRequest request = DefaultHttpRequest.builder()
|
HttpRequest request = builder().method(requestMetadata.getMethod())
|
||||||
.method(requestMetadata.getMethod())
|
|
||||||
.path(requestMetadata.getPath())
|
.path(requestMetadata.getPath())
|
||||||
.params(requestMetadata.getParams())
|
.params(requestMetadata.getParams())
|
||||||
.headers(requestMetadata.getHeaders()).build();
|
.headers(requestMetadata.getHeaders()).build();
|
||||||
@ -491,8 +509,7 @@ public class DubboServiceMetadataRepository {
|
|||||||
|
|
||||||
private void initSubscribedServices() {
|
private void initSubscribedServices() {
|
||||||
// If subscribes all services
|
// If subscribes all services
|
||||||
if (DubboCloudProperties.ALL_DUBBO_SERVICES
|
if (ALL_DUBBO_SERVICES.equals(dubboCloudProperties.getSubscribedServices())) {
|
||||||
.equals(dubboCloudProperties.getSubscribedServices())) {
|
|
||||||
List<String> services = discoveryClient.getServices();
|
List<String> services = discoveryClient.getServices();
|
||||||
subscribedServices = new HashSet<>(services);
|
subscribedServices = new HashSet<>(services);
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
|
@ -17,12 +17,13 @@
|
|||||||
package com.alibaba.cloud.dubbo.registry;
|
package com.alibaba.cloud.dubbo.registry;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.GROUP_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.PROTOCOL_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.PROVIDER_SIDE;
|
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||||
import static org.apache.dubbo.common.Constants.SIDE_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.VERSION_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||||
|
import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL;
|
||||||
import static org.springframework.util.StringUtils.hasText;
|
import static org.springframework.util.StringUtils.hasText;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -35,7 +36,6 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.dubbo.common.Constants;
|
|
||||||
import org.apache.dubbo.common.URL;
|
import org.apache.dubbo.common.URL;
|
||||||
import org.apache.dubbo.registry.NotifyListener;
|
import org.apache.dubbo.registry.NotifyListener;
|
||||||
import org.apache.dubbo.registry.RegistryFactory;
|
import org.apache.dubbo.registry.RegistryFactory;
|
||||||
@ -66,7 +66,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
protected static final String DUBBO_METADATA_SERVICE_CLASS_NAME = DubboMetadataService.class
|
protected static final String DUBBO_METADATA_SERVICE_CLASS_NAME = DubboMetadataService.class
|
||||||
.getName();
|
.getName();
|
||||||
|
|
||||||
private static final Set<String> schedulerTasks = new HashSet<>();
|
private static final Set<String> SCHEDULER_TASKS = new HashSet<>();
|
||||||
|
|
||||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
|
|
||||||
private void submitSchedulerTaskIfAbsent(URL url, NotifyListener listener) {
|
private void submitSchedulerTaskIfAbsent(URL url, NotifyListener listener) {
|
||||||
String taskId = url.toIdentityString();
|
String taskId = url.toIdentityString();
|
||||||
if (schedulerTasks.add(taskId)) {
|
if (SCHEDULER_TASKS.add(taskId)) {
|
||||||
schedule(() -> doSubscribeDubboServiceURLs(url, listener));
|
schedule(() -> doSubscribeDubboServiceURLs(url, listener));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isAdminURL(URL url) {
|
protected boolean isAdminURL(URL url) {
|
||||||
return Constants.ADMIN_PROTOCOL.equals(url.getProtocol());
|
return ADMIN_PROTOCOL.equals(url.getProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isDubboMetadataServiceURL(URL url) {
|
protected boolean isDubboMetadataServiceURL(URL url) {
|
||||||
|
@ -42,6 +42,10 @@ import com.alibaba.cloud.dubbo.util.JSONUtils;
|
|||||||
*/
|
*/
|
||||||
public class SpringCloudRegistryFactory implements RegistryFactory {
|
public class SpringCloudRegistryFactory implements RegistryFactory {
|
||||||
|
|
||||||
|
public static String PROTOCOL = "spring-cloud";
|
||||||
|
|
||||||
|
public static String ADDRESS = "localhost";
|
||||||
|
|
||||||
private static String SERVICES_LOOKUP_SCHEDULER_THREAD_NAME_PREFIX = getProperty(
|
private static String SERVICES_LOOKUP_SCHEDULER_THREAD_NAME_PREFIX = getProperty(
|
||||||
"dubbo.services.lookup.scheduler.thread.name.prefix ",
|
"dubbo.services.lookup.scheduler.thread.name.prefix ",
|
||||||
"dubbo-services-lookup-");
|
"dubbo-services-lookup-");
|
||||||
|
@ -17,12 +17,13 @@
|
|||||||
package com.alibaba.cloud.dubbo.service;
|
package com.alibaba.cloud.dubbo.service;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
import static org.apache.dubbo.common.Constants.GROUP_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||||
import static org.apache.dubbo.common.Constants.VERSION_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||||
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
|
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
|
||||||
|
|
||||||
import java.beans.PropertyEditorSupport;
|
import java.beans.PropertyEditorSupport;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -32,11 +33,14 @@ import javax.annotation.PreDestroy;
|
|||||||
|
|
||||||
import org.apache.dubbo.common.URL;
|
import org.apache.dubbo.common.URL;
|
||||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||||
|
import org.apache.dubbo.config.RegistryConfig;
|
||||||
import org.apache.dubbo.config.spring.ReferenceBean;
|
import org.apache.dubbo.config.spring.ReferenceBean;
|
||||||
import org.apache.dubbo.rpc.service.GenericService;
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.validation.DataBinder;
|
import org.springframework.validation.DataBinder;
|
||||||
@ -55,6 +59,9 @@ public class DubboGenericServiceFactory {
|
|||||||
|
|
||||||
private final ConcurrentMap<Integer, ReferenceBean<GenericService>> cache = new ConcurrentHashMap<>();
|
private final ConcurrentMap<Integer, ReferenceBean<GenericService>> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectProvider<List<RegistryConfig>> registryConfigs;
|
||||||
|
|
||||||
public GenericService create(DubboRestServiceMetadata dubboServiceMetadata,
|
public GenericService create(DubboRestServiceMetadata dubboServiceMetadata,
|
||||||
Map<String, Object> dubboTranslatedAttributes) {
|
Map<String, Object> dubboTranslatedAttributes) {
|
||||||
|
|
||||||
@ -89,18 +96,15 @@ public class DubboGenericServiceFactory {
|
|||||||
Integer key = Objects.hash(interfaceName, version, group,
|
Integer key = Objects.hash(interfaceName, version, group,
|
||||||
dubboTranslatedAttributes);
|
dubboTranslatedAttributes);
|
||||||
|
|
||||||
ReferenceBean<GenericService> referenceBean = cache.get(key);
|
return cache.computeIfAbsent(key, k -> {
|
||||||
|
ReferenceBean<GenericService> referenceBean = new ReferenceBean<>();
|
||||||
if (referenceBean == null) {
|
|
||||||
referenceBean = new ReferenceBean<>();
|
|
||||||
referenceBean.setGeneric(true);
|
referenceBean.setGeneric(true);
|
||||||
referenceBean.setInterface(interfaceName);
|
referenceBean.setInterface(interfaceName);
|
||||||
referenceBean.setVersion(version);
|
referenceBean.setVersion(version);
|
||||||
referenceBean.setGroup(group);
|
referenceBean.setGroup(group);
|
||||||
bindReferenceBean(referenceBean, dubboTranslatedAttributes);
|
bindReferenceBean(referenceBean, dubboTranslatedAttributes);
|
||||||
}
|
return referenceBean;
|
||||||
|
});
|
||||||
return referenceBean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindReferenceBean(ReferenceBean<GenericService> referenceBean,
|
private void bindReferenceBean(ReferenceBean<GenericService> referenceBean,
|
||||||
@ -133,7 +137,12 @@ public class DubboGenericServiceFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ignore "registries" field and then use RegistryConfig beans
|
||||||
|
dataBinder.setDisallowedFields("registries");
|
||||||
|
|
||||||
dataBinder.bind(new MutablePropertyValues(dubboTranslatedAttributes));
|
dataBinder.bind(new MutablePropertyValues(dubboTranslatedAttributes));
|
||||||
|
|
||||||
|
registryConfigs.ifAvailable(referenceBean::setRegistries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
@ -155,4 +164,4 @@ public class DubboGenericServiceFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user