mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
6880e4bd7b
@ -70,7 +70,7 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目 clone
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
<version>2.2.0.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -45,7 +45,7 @@ For more features, please refer to [Roadmap](https://github.com/alibaba/spring-c
|
|||||||
|
|
||||||
**[Alibaba Cloud SMS](https://www.aliyun.com/product/sms)**: A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers.
|
**[Alibaba Cloud SMS](https://www.aliyun.com/product/sms)**: A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers.
|
||||||
|
|
||||||
**[Alibaba Cloud SchedulerX](https://www.aliyun.com/product/SchedulerX)**:accurate, highly reliable, and highly available scheduled job scheduling services with response time within seconds..
|
**[Alibaba Cloud SchedulerX](https://www.aliyun.com/aliware/schedulerx?spm=5176.10695662.784137.1.4b07363dej23L3)**:accurate, highly reliable, and highly available scheduled job scheduling services with response time within seconds..
|
||||||
|
|
||||||
For more features please refer to [Roadmap](https://github.com/alibaba/spring-cloud-alibaba/blob/master/Roadmap.md).
|
For more features please refer to [Roadmap](https://github.com/alibaba/spring-cloud-alibaba/blob/master/Roadmap.md).
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ These artifacts are available from Maven Central and Spring Release repository v
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
<version>2.2.1.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
2
pom.xml
2
pom.xml
@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Project revision -->
|
<!-- Project revision -->
|
||||||
<revision>2.2.2-SNAPSHOT</revision>
|
<revision>2.2.2.RELEASE</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.2-SNAPSHOT</revision>
|
<revision>2.2.2.RELEASE</revision>
|
||||||
<sentinel.version>1.8.0</sentinel.version>
|
<sentinel.version>1.8.0</sentinel.version>
|
||||||
<oss.version>3.1.0</oss.version>
|
<oss.version>3.1.0</oss.version>
|
||||||
<seata.version>1.3.0</seata.version>
|
<seata.version>1.3.0</seata.version>
|
||||||
|
@ -10,7 +10,7 @@ Spring Cloud Alibaba BOM 包含了它所使用的所有依赖的版本。
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
<version>2.2.0.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -8,7 +8,7 @@ If you’re a Maven Central user, add our BOM to your pom.xml <dependencyManagem
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
<version>2.2.0.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -25,10 +25,10 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class OderApplication {
|
public class OrderApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(OderApplication.class, args);
|
SpringApplication.run(OrderApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
@ -67,8 +67,12 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
|||||||
if (!StringUtils.isEmpty(this.namespace)) {
|
if (!StringUtils.isEmpty(this.namespace)) {
|
||||||
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
||||||
}
|
}
|
||||||
|
if (!StringUtils.isEmpty(this.username)) {
|
||||||
properties.setProperty(PropertyKeyConst.USERNAME, this.username);
|
properties.setProperty(PropertyKeyConst.USERNAME, this.username);
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(this.password)) {
|
||||||
properties.setProperty(PropertyKeyConst.PASSWORD, this.password);
|
properties.setProperty(PropertyKeyConst.PASSWORD, this.password);
|
||||||
|
}
|
||||||
return new NacosDataSource(properties, groupId, dataId, converter);
|
return new NacosDataSource(properties, groupId, dataId, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,14 +23,14 @@ import java.util.Enumeration;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
|
import com.alibaba.cloud.nacos.event.NacosDiscoveryInfoChangedEvent;
|
||||||
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||||
import com.alibaba.spring.util.PropertySourcesUtils;
|
import com.alibaba.spring.util.PropertySourcesUtils;
|
||||||
@ -41,6 +41,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.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.commons.util.InetUtils;
|
import org.springframework.cloud.commons.util.InetUtils;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -216,7 +217,7 @@ public class NacosDiscoveryProperties {
|
|||||||
private NacosServiceManager nacosServiceManager;
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Optional<NacosAutoServiceRegistration> nacosAutoServiceRegistrationOptional;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
@ -266,14 +267,19 @@ public class NacosDiscoveryProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.overrideFromEnv(environment);
|
this.overrideFromEnv(environment);
|
||||||
|
|
||||||
nacosAutoServiceRegistrationOptional.ifPresent(nacosAutoServiceRegistration -> {
|
|
||||||
if (nacosServiceManager.isNacosDiscoveryInfoChanged(this)) {
|
if (nacosServiceManager.isNacosDiscoveryInfoChanged(this)) {
|
||||||
nacosAutoServiceRegistration.stop();
|
applicationEventPublisher
|
||||||
nacosServiceManager.reBuildNacosService(getNacosProperties());
|
.publishEvent(new NacosDiscoveryInfoChangedEvent(this));
|
||||||
nacosAutoServiceRegistration.start();
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* recommend to use {@link NacosServiceManager#getNamingService(Properties)}.
|
||||||
|
* @return NamingService
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public NamingService namingServiceInstance() {
|
||||||
|
return nacosServiceManager.getNamingService(this.getNacosProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEndpoint() {
|
public String getEndpoint() {
|
||||||
|
@ -23,6 +23,8 @@ import com.alibaba.cloud.nacos.registry.NacosRegistration;
|
|||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent;
|
import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent;
|
||||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||||
@ -37,6 +39,8 @@ import static org.springframework.beans.BeanUtils.copyProperties;
|
|||||||
*/
|
*/
|
||||||
public class NacosServiceManager {
|
public class NacosServiceManager {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(NacosServiceManager.class);
|
||||||
|
|
||||||
private NacosDiscoveryProperties nacosDiscoveryPropertiesCache;
|
private NacosDiscoveryProperties nacosDiscoveryPropertiesCache;
|
||||||
|
|
||||||
private NamingService namingService;
|
private NamingService namingService;
|
||||||
@ -107,13 +111,10 @@ public class NacosServiceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reBuildNacosService(Properties nacosProperties) {
|
|
||||||
namingService = createNewNamingService(nacosProperties);
|
|
||||||
namingMaintainService = createNamingMaintainService(nacosProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void nacosServiceShutDown() throws NacosException {
|
public void nacosServiceShutDown() throws NacosException {
|
||||||
this.namingService.shutDown();
|
this.namingService.shutDown();
|
||||||
|
namingService = null;
|
||||||
|
namingMaintainService = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
|
@ -18,8 +18,8 @@ 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 com.alibaba.cloud.nacos.NacosServiceManager;
|
||||||
|
|
||||||
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;
|
||||||
@ -31,7 +31,6 @@ 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
|
||||||
@ -56,9 +55,9 @@ public class NacosDiscoveryClientConfiguration {
|
|||||||
@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(NacosServiceManager nacosServiceManager,
|
||||||
ObjectProvider<TaskScheduler> taskScheduler) {
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
return new NacosWatch(nacosDiscoveryProperties, taskScheduler);
|
return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,67 +16,54 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.nacos.discovery;
|
package com.alibaba.cloud.nacos.discovery;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
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.cloud.nacos.NacosServiceManager;
|
||||||
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
import com.alibaba.nacos.api.naming.listener.Event;
|
||||||
|
import com.alibaba.nacos.api.naming.listener.EventListener;
|
||||||
|
import com.alibaba.nacos.api.naming.listener.NamingEvent;
|
||||||
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
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;
|
||||||
import org.springframework.context.SmartLifecycle;
|
import org.springframework.context.SmartLifecycle;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
|
* @author yuhuangbin
|
||||||
*/
|
*/
|
||||||
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
||||||
|
|
||||||
private final NacosDiscoveryProperties properties;
|
private Map<String, EventListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||||
|
|
||||||
private final TaskScheduler taskScheduler;
|
|
||||||
|
|
||||||
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
|
||||||
|
|
||||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
||||||
|
|
||||||
private ApplicationEventPublisher publisher;
|
private ApplicationEventPublisher publisher;
|
||||||
|
|
||||||
private ScheduledFuture<?> watchFuture;
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
|
||||||
public NacosWatch(NacosDiscoveryProperties properties) {
|
private final NacosDiscoveryProperties properties;
|
||||||
this(properties, getTaskScheduler());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NacosWatch(NacosDiscoveryProperties properties, TaskScheduler taskScheduler) {
|
public NacosWatch(NacosServiceManager nacosServiceManager,
|
||||||
|
NacosDiscoveryProperties properties) {
|
||||||
|
this.nacosServiceManager = nacosServiceManager;
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
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() {
|
|
||||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
|
||||||
taskScheduler.setBeanName("Nacos-Watch-Task-Scheduler");
|
|
||||||
taskScheduler.initialize();
|
|
||||||
return taskScheduler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -98,19 +85,67 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
|
|||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (this.running.compareAndSet(false, true)) {
|
if (this.running.compareAndSet(false, true)) {
|
||||||
this.watchFuture = this.taskScheduler.scheduleWithFixedDelay(
|
EventListener eventListener = listenerMap.computeIfAbsent(buildKey(),
|
||||||
this::nacosServicesWatch, this.properties.getWatchDelay());
|
event -> new EventListener() {
|
||||||
|
@Override
|
||||||
|
public void onEvent(Event event) {
|
||||||
|
if (event instanceof NamingEvent) {
|
||||||
|
List<Instance> instances = ((NamingEvent) event)
|
||||||
|
.getInstances();
|
||||||
|
Optional<Instance> instanceOptional = selectCurrentInstance(
|
||||||
|
instances);
|
||||||
|
instanceOptional.ifPresent(currentInstance -> {
|
||||||
|
resetIfNeeded(currentInstance);
|
||||||
|
});
|
||||||
|
publisher.publishEvent(new HeartbeatEvent(NacosWatch.this,
|
||||||
|
nacosWatchIndex.getAndIncrement()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
NamingService namingService = nacosServiceManager
|
||||||
|
.getNamingService(properties.getNacosProperties());
|
||||||
|
try {
|
||||||
|
namingService.subscribe(properties.getService(), properties.getGroup(),
|
||||||
|
Arrays.asList(properties.getClusterName()), eventListener);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error("namingService subscribe failed, properties:{}", properties, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildKey() {
|
||||||
|
return String.join(":", properties.getService(), properties.getGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetIfNeeded(Instance instance) {
|
||||||
|
if (!properties.getMetadata().equals(instance.getMetadata())) {
|
||||||
|
properties.setMetadata(instance.getMetadata());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<Instance> selectCurrentInstance(List<Instance> instances) {
|
||||||
|
return instances.stream()
|
||||||
|
.filter(instance -> properties.getIp().equals(instance.getIp())
|
||||||
|
&& properties.getPort() == instance.getPort())
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (this.running.compareAndSet(true, false) && this.watchFuture != null) {
|
if (this.running.compareAndSet(true, false)) {
|
||||||
// shutdown current user-thread,
|
EventListener eventListener = listenerMap.get(buildKey());
|
||||||
// then the other daemon-threads will terminate automatic.
|
NamingService namingService = nacosServiceManager
|
||||||
((ThreadPoolTaskScheduler) this.taskScheduler).shutdown();
|
.getNamingService(properties.getNacosProperties());
|
||||||
|
try {
|
||||||
this.watchFuture.cancel(true);
|
namingService.unsubscribe(properties.getService(), properties.getGroup(),
|
||||||
|
Arrays.asList(properties.getClusterName()), eventListener);
|
||||||
|
}
|
||||||
|
catch (NacosException e) {
|
||||||
|
log.error("namingService unsubscribe failed, properties:{}", properties,
|
||||||
|
e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +159,4 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nacosServicesWatch() {
|
|
||||||
|
|
||||||
// nacos doesn't support watch now , publish an event every 30 seconds.
|
|
||||||
this.publisher.publishEvent(
|
|
||||||
new HeartbeatEvent(this, nacosWatchIndex.getAndIncrement()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.event;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuhuangbin
|
||||||
|
*/
|
||||||
|
public class NacosDiscoveryInfoChangedEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
public NacosDiscoveryInfoChangedEvent(
|
||||||
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
|
super(nacosDiscoveryProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NacosDiscoveryProperties getSource() {
|
||||||
|
return (NacosDiscoveryProperties) super.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.nacos.registry;
|
package com.alibaba.cloud.nacos.registry;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.event.NacosDiscoveryInfoChangedEvent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegis
|
|||||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
|
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
|
||||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@ -102,4 +104,14 @@ public class NacosAutoServiceRegistration
|
|||||||
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
|
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventListener
|
||||||
|
public void onNacosDiscoveryInfoChangedEvent(NacosDiscoveryInfoChangedEvent event) {
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restart() {
|
||||||
|
this.stop();
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
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;
|
||||||
@ -44,12 +45,11 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
|
|
||||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private NacosServiceManager nacosServiceManager;
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
|
||||||
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties,
|
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
NacosServiceManager nacosServiceManager) {
|
|
||||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||||
this.nacosServiceManager = nacosServiceManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,6 @@ import java.util.List;
|
|||||||
|
|
||||||
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.NacosServiceManager;
|
|
||||||
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
|
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
@ -51,9 +50,8 @@ public class NacosServiceRegistryAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public NacosServiceRegistry nacosServiceRegistry(
|
public NacosServiceRegistry nacosServiceRegistry(
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties,
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
NacosServiceManager nacosServiceManager) {
|
return new NacosServiceRegistry(nacosDiscoveryProperties);
|
||||||
return new NacosServiceRegistry(nacosDiscoveryProperties, nacosServiceManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package com.alibaba.cloud.nacos.ribbon;
|
package com.alibaba.cloud.nacos.ribbon;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
|
||||||
import com.netflix.client.config.IClientConfig;
|
import com.netflix.client.config.IClientConfig;
|
||||||
import com.netflix.loadbalancer.ServerList;
|
import com.netflix.loadbalancer.ServerList;
|
||||||
|
|
||||||
@ -43,15 +42,13 @@ public class NacosRibbonClientConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public ServerList<?> ribbonServerList(IClientConfig config,
|
public ServerList<?> ribbonServerList(IClientConfig config,
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties,
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
NacosServiceManager nacosServiceManager) {
|
|
||||||
if (this.propertiesFactory.isSet(ServerList.class, config.getClientName())) {
|
if (this.propertiesFactory.isSet(ServerList.class, config.getClientName())) {
|
||||||
ServerList serverList = this.propertiesFactory.get(ServerList.class, config,
|
ServerList serverList = this.propertiesFactory.get(ServerList.class, config,
|
||||||
config.getClientName());
|
config.getClientName());
|
||||||
return serverList;
|
return serverList;
|
||||||
}
|
}
|
||||||
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties,
|
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties);
|
||||||
nacosServiceManager);
|
|
||||||
serverList.initWithNiwsConfig(config);
|
serverList.initWithNiwsConfig(config);
|
||||||
return serverList;
|
return serverList;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.netflix.client.config.IClientConfig;
|
import com.netflix.client.config.IClientConfig;
|
||||||
@ -34,14 +33,10 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
|
|||||||
|
|
||||||
private NacosDiscoveryProperties discoveryProperties;
|
private NacosDiscoveryProperties discoveryProperties;
|
||||||
|
|
||||||
private NacosServiceManager nacosServiceManager;
|
|
||||||
|
|
||||||
private String serviceId;
|
private String serviceId;
|
||||||
|
|
||||||
public NacosServerList(NacosDiscoveryProperties discoveryProperties,
|
public NacosServerList(NacosDiscoveryProperties discoveryProperties) {
|
||||||
NacosServiceManager nacosServiceManager) {
|
|
||||||
this.discoveryProperties = discoveryProperties;
|
this.discoveryProperties = discoveryProperties;
|
||||||
this.nacosServiceManager = nacosServiceManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,8 +52,7 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
|
|||||||
private List<NacosServer> getServers() {
|
private List<NacosServer> getServers() {
|
||||||
try {
|
try {
|
||||||
String group = discoveryProperties.getGroup();
|
String group = discoveryProperties.getGroup();
|
||||||
List<Instance> instances = nacosServiceManager
|
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
||||||
.getNamingService(discoveryProperties.getNacosProperties())
|
|
||||||
.selectInstances(serviceId, group, true);
|
.selectInstances(serviceId, group, true);
|
||||||
return instancesToServerList(instances);
|
return instancesToServerList(instances);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
|
||||||
import com.alibaba.cloud.nacos.test.NacosMockTest;
|
import com.alibaba.cloud.nacos.test.NacosMockTest;
|
||||||
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.Instance;
|
||||||
@ -49,16 +48,12 @@ public class NacosServerListTests {
|
|||||||
NacosDiscoveryProperties.class);
|
NacosDiscoveryProperties.class);
|
||||||
|
|
||||||
NamingService namingService = mock(NamingService.class);
|
NamingService namingService = mock(NamingService.class);
|
||||||
NacosServiceManager nacosServiceManager = mock(NacosServiceManager.class);
|
|
||||||
|
|
||||||
when(nacosServiceManager
|
when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService);
|
||||||
.getNamingService(nacosDiscoveryProperties.getNacosProperties()))
|
|
||||||
.thenReturn(namingService);
|
|
||||||
when(namingService.selectInstances(anyString(), eq("DEFAULT"), eq(true)))
|
when(namingService.selectInstances(anyString(), eq("DEFAULT"), eq(true)))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties,
|
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties);
|
||||||
nacosServiceManager);
|
|
||||||
List<NacosServer> servers = serverList.getInitialListOfServers();
|
List<NacosServer> servers = serverList.getInitialListOfServers();
|
||||||
assertThat(servers).isEmpty();
|
assertThat(servers).isEmpty();
|
||||||
}
|
}
|
||||||
@ -73,13 +68,10 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
||||||
NacosDiscoveryProperties.class);
|
NacosDiscoveryProperties.class);
|
||||||
NacosServiceManager nacosServiceManager = mock(NacosServiceManager.class);
|
|
||||||
|
|
||||||
NamingService namingService = mock(NamingService.class);
|
NamingService namingService = mock(NamingService.class);
|
||||||
|
|
||||||
when(nacosServiceManager
|
when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService);
|
||||||
.getNamingService(nacosDiscoveryProperties.getNacosProperties()))
|
|
||||||
.thenReturn(namingService);
|
|
||||||
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
||||||
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
||||||
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
||||||
@ -87,8 +79,7 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
IClientConfig clientConfig = mock(IClientConfig.class);
|
IClientConfig clientConfig = mock(IClientConfig.class);
|
||||||
when(clientConfig.getClientName()).thenReturn("test-service");
|
when(clientConfig.getClientName()).thenReturn("test-service");
|
||||||
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties,
|
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties);
|
||||||
nacosServiceManager);
|
|
||||||
serverList.initWithNiwsConfig(clientConfig);
|
serverList.initWithNiwsConfig(clientConfig);
|
||||||
List<NacosServer> servers = serverList.getInitialListOfServers();
|
List<NacosServer> servers = serverList.getInitialListOfServers();
|
||||||
assertThat(servers).hasSize(1);
|
assertThat(servers).hasSize(1);
|
||||||
@ -111,13 +102,10 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
||||||
NacosDiscoveryProperties.class);
|
NacosDiscoveryProperties.class);
|
||||||
NacosServiceManager nacosServiceManager = mock(NacosServiceManager.class);
|
|
||||||
|
|
||||||
NamingService namingService = mock(NamingService.class);
|
NamingService namingService = mock(NamingService.class);
|
||||||
|
|
||||||
when(nacosServiceManager
|
when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService);
|
||||||
.getNamingService(nacosDiscoveryProperties.getNacosProperties()))
|
|
||||||
.thenReturn(namingService);
|
|
||||||
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
||||||
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
||||||
.thenReturn(instances.stream().filter(Instance::isHealthy)
|
.thenReturn(instances.stream().filter(Instance::isHealthy)
|
||||||
@ -125,8 +113,7 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
IClientConfig clientConfig = mock(IClientConfig.class);
|
IClientConfig clientConfig = mock(IClientConfig.class);
|
||||||
when(clientConfig.getClientName()).thenReturn("test-service");
|
when(clientConfig.getClientName()).thenReturn("test-service");
|
||||||
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties,
|
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties);
|
||||||
nacosServiceManager);
|
|
||||||
serverList.initWithNiwsConfig(clientConfig);
|
serverList.initWithNiwsConfig(clientConfig);
|
||||||
List<NacosServer> servers = serverList.getInitialListOfServers();
|
List<NacosServer> servers = serverList.getInitialListOfServers();
|
||||||
assertThat(servers).hasSize(1);
|
assertThat(servers).hasSize(1);
|
||||||
@ -153,13 +140,10 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
NacosDiscoveryProperties nacosDiscoveryProperties = mock(
|
||||||
NacosDiscoveryProperties.class);
|
NacosDiscoveryProperties.class);
|
||||||
NacosServiceManager nacosServiceManager = mock(NacosServiceManager.class);
|
|
||||||
|
|
||||||
NamingService namingService = mock(NamingService.class);
|
NamingService namingService = mock(NamingService.class);
|
||||||
|
|
||||||
when(nacosServiceManager
|
when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService);
|
||||||
.getNamingService(nacosDiscoveryProperties.getNacosProperties()))
|
|
||||||
.thenReturn(namingService);
|
|
||||||
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
|
||||||
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true)))
|
||||||
.thenReturn(instances.stream().filter(Instance::isHealthy)
|
.thenReturn(instances.stream().filter(Instance::isHealthy)
|
||||||
@ -167,8 +151,7 @@ public class NacosServerListTests {
|
|||||||
|
|
||||||
IClientConfig clientConfig = mock(IClientConfig.class);
|
IClientConfig clientConfig = mock(IClientConfig.class);
|
||||||
when(clientConfig.getClientName()).thenReturn("test-service");
|
when(clientConfig.getClientName()).thenReturn("test-service");
|
||||||
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties,
|
NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties);
|
||||||
nacosServiceManager);
|
|
||||||
serverList.initWithNiwsConfig(clientConfig);
|
serverList.initWithNiwsConfig(clientConfig);
|
||||||
|
|
||||||
List<NacosServer> servers = serverList.getUpdatedListOfServers();
|
List<NacosServer> servers = serverList.getUpdatedListOfServers();
|
||||||
|
@ -41,7 +41,8 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
.getLogger(SeataHandlerInterceptor.class);
|
.getLogger(SeataHandlerInterceptor.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
Object handler) {
|
||||||
String xid = RootContext.getXID();
|
String xid = RootContext.getXID();
|
||||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -58,9 +59,9 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
Object handler, Exception e) {
|
||||||
if (StringUtils.isNotBlank(RootContext.getXID())) {
|
if (StringUtils.isNotBlank(RootContext.getXID())) {
|
||||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user