mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #1197 from mercyblitz/master
Dubbo And Nacos Updates
This commit is contained in:
commit
b72d468be1
39
pom.xml
39
pom.xml
@ -88,8 +88,7 @@
|
|||||||
<slf4j-api.version>1.7.25</slf4j-api.version>
|
<slf4j-api.version>1.7.25</slf4j-api.version>
|
||||||
|
|
||||||
<!-- Apache Dubbo -->
|
<!-- Apache Dubbo -->
|
||||||
<dubbo-spring-boot.version>2.7.3</dubbo-spring-boot.version>
|
<dubbo.version>2.7.4.1</dubbo.version>
|
||||||
<dubbo.version>2.7.3</dubbo.version>
|
|
||||||
<curator.version>4.0.1</curator.version>
|
<curator.version>4.0.1</curator.version>
|
||||||
|
|
||||||
<!-- Apache RocketMQ -->
|
<!-- Apache RocketMQ -->
|
||||||
@ -132,7 +131,7 @@
|
|||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring Boot -->
|
<!-- Spring Dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
@ -228,10 +227,31 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Dubbo Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.dubbo</groupId>
|
||||||
|
<artifactId>dubbo-dependencies-bom</artifactId>
|
||||||
|
<version>${dubbo.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-framework-bom</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<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>
|
||||||
|
<groupId>org.apache.dubbo</groupId>
|
||||||
|
<artifactId>dubbo-spring-boot-actuator</artifactId>
|
||||||
|
<version>${dubbo.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -241,15 +261,7 @@
|
|||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -420,5 +432,4 @@
|
|||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -13,30 +13,6 @@
|
|||||||
<artifactId>spring-cloud-alibaba-dubbo</artifactId>
|
<artifactId>spring-cloud-alibaba-dubbo</artifactId>
|
||||||
<name>Spring Cloud Alibaba Dubbo</name>
|
<name>Spring Cloud Alibaba Dubbo</name>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Spring Boot dependencies -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Apache Dubbo dependencies-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.dubbo</groupId>
|
|
||||||
<artifactId>dubbo-dependencies-bom</artifactId>
|
|
||||||
<version>${dubbo.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
@ -162,7 +138,6 @@
|
|||||||
<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-spring-boot.version}</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
|||||||
/**
|
/**
|
||||||
* NacosDiscoveryAutoConfiguration.
|
* NacosDiscoveryAutoConfiguration.
|
||||||
*/
|
*/
|
||||||
public static final String NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME = "com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration";
|
public static final String NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME = "com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration";
|
||||||
|
|
||||||
private final DubboServiceMetadataRepository dubboServiceMetadataRepository;
|
private final DubboServiceMetadataRepository dubboServiceMetadataRepository;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
||||||
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties;
|
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getPrefixedProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Missing {@link SpringCloudRegistry} Property {@link Condition}.
|
* Missing {@link SpringCloudRegistry} Property {@link Condition}.
|
||||||
@ -61,8 +61,8 @@ public class MissingSpringCloudRegistryConfigPropertyCondition
|
|||||||
"'spring-cloud' protocol was found from 'dubbo.registry.address'");
|
"'spring-cloud' protocol was found from 'dubbo.registry.address'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> properties = getSubProperties(environment,
|
Map<String, Object> properties = getPrefixedProperties(
|
||||||
"dubbo.registries.");
|
environment.getPropertySources(), "dubbo.registries.");
|
||||||
|
|
||||||
boolean found = properties.entrySet().stream().anyMatch(entry -> {
|
boolean found = properties.entrySet().stream().anyMatch(entry -> {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
|
@ -35,7 +35,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.apache.dubbo.common.constants.CommonConstants.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.getPrefixedProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dubbo {@link WebApplicationType#NONE Non-Web Application}
|
* Dubbo {@link WebApplicationType#NONE Non-Web Application}
|
||||||
@ -88,7 +88,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
|||||||
WebApplicationType webApplicationType = application.getWebApplicationType();
|
WebApplicationType webApplicationType = application.getWebApplicationType();
|
||||||
|
|
||||||
if (!WebApplicationType.NONE.equals(webApplicationType)) { // Just works in
|
if (!WebApplicationType.NONE.equals(webApplicationType)) { // Just works in
|
||||||
// Non-Web Application
|
// Non-Web Application
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Current application is a Web Application, the process will be ignored.");
|
"Current application is a Web Application, the process will be ignored.");
|
||||||
@ -149,8 +149,8 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
|||||||
|
|
||||||
String restPort = null;
|
String restPort = null;
|
||||||
|
|
||||||
Map<String, Object> subProperties = getSubProperties(environment,
|
Map<String, Object> subProperties = getPrefixedProperties(
|
||||||
PROTOCOLS_PROPERTY_NAME_PREFIX);
|
environment.getPropertySources(), PROTOCOLS_PROPERTY_NAME_PREFIX);
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
@ -158,8 +158,8 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
|||||||
|
|
||||||
for (String propertyName : properties.stringPropertyNames()) {
|
for (String propertyName : properties.stringPropertyNames()) {
|
||||||
if (propertyName.endsWith(PROTOCOL_NAME_PROPERTY_NAME_SUFFIX)) { // protocol
|
if (propertyName.endsWith(PROTOCOL_NAME_PROPERTY_NAME_SUFFIX)) { // protocol
|
||||||
// name
|
// name
|
||||||
// property
|
// property
|
||||||
String protocol = properties.getProperty(propertyName);
|
String protocol = properties.getProperty(propertyName);
|
||||||
if (isRestProtocol(protocol)) {
|
if (isRestProtocol(protocol)) {
|
||||||
String beanName = resolveBeanName(propertyName);
|
String beanName = resolveBeanName(propertyName);
|
||||||
|
@ -136,18 +136,6 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.dubbo</groupId>
|
|
||||||
<artifactId>dubbo-bom</artifactId>
|
|
||||||
<version>${dubbo.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -20,9 +20,13 @@ import com.alibaba.nacos.api.config.ConfigService;
|
|||||||
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.Health;
|
import org.springframework.boot.actuate.health.Health;
|
||||||
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The {@link HealthIndicator} for Nacos Config
|
||||||
|
*
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
*/
|
*/
|
||||||
public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
@ -34,10 +38,21 @@ public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||||
builder.up();
|
// Just return "UP" or "DOWN"
|
||||||
|
|
||||||
String status = configService.getServerStatus();
|
String status = configService.getServerStatus();
|
||||||
|
// Set the status to Builder
|
||||||
builder.status(status);
|
builder.status(status);
|
||||||
|
switch (status) {
|
||||||
|
case "UP":
|
||||||
|
builder.up();
|
||||||
|
break;
|
||||||
|
case "DOWN":
|
||||||
|
builder.down();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
builder.unknown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package com.alibaba.cloud.nacos.discovery;
|
|||||||
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
|
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
@ -30,6 +31,7 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|||||||
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
@ -52,10 +54,10 @@ public class NacosDiscoveryClientConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled",
|
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
|
||||||
matchIfMissing = true)
|
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties,
|
||||||
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
ObjectProvider<TaskScheduler> taskScheduler) {
|
||||||
return new NacosWatch(nacosDiscoveryProperties);
|
return new NacosWatch(nacosDiscoveryProperties, taskScheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.nacos.discovery;
|
package com.alibaba.cloud.nacos.discovery;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.nacos.api.naming.listener.EventListener;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.ApplicationEventPublisherAware;
|
import org.springframework.context.ApplicationEventPublisherAware;
|
||||||
@ -54,10 +51,6 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
|
|||||||
|
|
||||||
private ScheduledFuture<?> watchFuture;
|
private ScheduledFuture<?> watchFuture;
|
||||||
|
|
||||||
private Set<String> cacheServices = new HashSet<>();
|
|
||||||
|
|
||||||
private HashMap<String, EventListener> subscribeListeners = new HashMap<>();
|
|
||||||
|
|
||||||
public NacosWatch(NacosDiscoveryProperties properties) {
|
public NacosWatch(NacosDiscoveryProperties properties) {
|
||||||
this(properties, getTaskScheduler());
|
this(properties, getTaskScheduler());
|
||||||
}
|
}
|
||||||
@ -67,8 +60,21 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
|
|||||||
this.taskScheduler = taskScheduler;
|
this.taskScheduler = taskScheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor with {@link NacosDiscoveryProperties} bean and the optional
|
||||||
|
* {@link TaskScheduler} bean
|
||||||
|
* @param properties {@link NacosDiscoveryProperties} bean
|
||||||
|
* @param taskScheduler the optional {@link TaskScheduler} bean
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
public NacosWatch(NacosDiscoveryProperties properties,
|
||||||
|
ObjectProvider<TaskScheduler> taskScheduler) {
|
||||||
|
this(properties, taskScheduler.getIfAvailable(NacosWatch::getTaskScheduler));
|
||||||
|
}
|
||||||
|
|
||||||
private static ThreadPoolTaskScheduler getTaskScheduler() {
|
private static ThreadPoolTaskScheduler getTaskScheduler() {
|
||||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||||
|
taskScheduler.setBeanName("Nacso-Watch-Task-Scheduler");
|
||||||
taskScheduler.initialize();
|
taskScheduler.initialize();
|
||||||
return taskScheduler;
|
return taskScheduler;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.nacos.discovery.actuate.health;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.Health;
|
||||||
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link HealthIndicator} for Nacos Discovery
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @since 2.2.0
|
||||||
|
* @see HealthIndicator
|
||||||
|
*/
|
||||||
|
public class NacosDiscoveryHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
|
private final NamingService namingService;
|
||||||
|
|
||||||
|
public NacosDiscoveryHealthIndicator(NamingService namingService) {
|
||||||
|
this.namingService = namingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||||
|
// Just return "UP" or "DOWN"
|
||||||
|
String status = namingService.getServerStatus();
|
||||||
|
// Set the status to Builder
|
||||||
|
builder.status(status);
|
||||||
|
switch (status) {
|
||||||
|
case "UP":
|
||||||
|
builder.up();
|
||||||
|
break;
|
||||||
|
case "DOWN":
|
||||||
|
builder.down();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
builder.unknown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,16 +18,22 @@ package com.alibaba.cloud.nacos.endpoint;
|
|||||||
|
|
||||||
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
|
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
import com.alibaba.cloud.nacos.discovery.actuate.health.NacosDiscoveryHealthIndicator;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||||
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;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The AutoConfiguration class for Nacos Discovery's Endpoints
|
||||||
|
*
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(Endpoint.class)
|
@ConditionalOnClass(Endpoint.class)
|
||||||
@ -42,4 +48,11 @@ public class NacosDiscoveryEndpointAutoConfiguration {
|
|||||||
return new NacosDiscoveryEndpoint(nacosDiscoveryProperties);
|
return new NacosDiscoveryEndpoint(nacosDiscoveryProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnEnabledHealthIndicator("nacos-discovery")
|
||||||
|
public HealthIndicator nacosDiscoveryHealthIndicator(
|
||||||
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
|
return new NacosDiscoveryHealthIndicator(
|
||||||
|
nacosDiscoveryProperties.namingServiceInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ import org.springframework.cloud.client.serviceregistry.Registration;
|
|||||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
@ -66,6 +68,9 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.error("nacos registry, {} register failed...{},", serviceId,
|
log.error("nacos registry, {} register failed...{},", serviceId,
|
||||||
registration.toString(), e);
|
registration.toString(), e);
|
||||||
|
// rethrow a RuntimeException if the registration is failed.
|
||||||
|
// issue : https://github.com/alibaba/spring-cloud-alibaba/issues/1132
|
||||||
|
rethrowRuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@ -33,7 +36,12 @@ public class NacosDiscoveryClientConfigurationTest {
|
|||||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
||||||
NacosDiscoveryAutoConfiguration.class,
|
NacosDiscoveryAutoConfiguration.class,
|
||||||
NacosDiscoveryClientConfiguration.class));
|
NacosDiscoveryClientConfiguration.class, this.getClass()));
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TaskScheduler taskScheduler() {
|
||||||
|
return new ThreadPoolTaskScheduler();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultInitialization() {
|
public void testDefaultInitialization() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user