Merge pull request #3 from alibaba/master

update
pull/1845/head
余黄彬 4 years ago committed by GitHub
commit 2f3460f3f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,7 +80,7 @@
<properties> <properties>
<!-- Project revision --> <!-- Project revision -->
<revision>2.2.3-SNAPSHOT</revision> <revision>2.2.4-SNAPSHOT</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.3.RELEASE</revision> <revision>2.2.4-SNAPSHOT</revision>
<sentinel.version>1.8.0</sentinel.version> <sentinel.version>1.8.0</sentinel.version>
<seata.version>1.3.0</seata.version> <seata.version>1.3.0</seata.version>
<nacos.client.version>1.3.3</nacos.client.version> <nacos.client.version>1.3.3</nacos.client.version>

@ -207,6 +207,7 @@ Metadata|spring.cloud.nacos.discovery.metadata||Extended data, Configure using M
log name|spring.cloud.nacos.discovery.log-name|| log name|spring.cloud.nacos.discovery.log-name||
endpoint|spring.cloud.nacos.discovery.endpoint||The domain name of a service, through which the server address can be dynamically obtained. endpoint|spring.cloud.nacos.discovery.endpoint||The domain name of a service, through which the server address can be dynamically obtained.
Integration Ribbon|ribbon.nacos.enabled|true| Integration Ribbon|ribbon.nacos.enabled|true|
enabled|spring.cloud.nacos.discovery.enabled|true|The switch to enable or disable nacos service discovery

@ -5,6 +5,8 @@ spring.cloud.nacos.discovery.server-addr=localhost:8848
#feign.hystrix.enabled=true #feign.hystrix.enabled=true
#feign.sentinel.enabled=true #feign.sentinel.enabled=true
feign.client.config.default.connectTimeout=10000
feign.client.config.default.readTimeout=10000
logging.level.io.seata=debug logging.level.io.seata=debug

@ -10,7 +10,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>order-service</artifactId> <artifactId>order-service</artifactId>
<name>Spring Cloud Starter Alibaba Seata Example - Business Service</name> <name>Spring Cloud Starter Alibaba Seata Example - Order Service</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>

@ -36,7 +36,7 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
* *
* @author xiaojing * @author xiaojing
*/ */
@Endpoint(id = "nacos-config") @Endpoint(id = "nacosconfig")
public class NacosConfigEndpoint { public class NacosConfigEndpoint {
private final NacosConfigProperties properties; private final NacosConfigProperties properties;

@ -32,7 +32,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; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/** /**
* @author xiaojing * @author xiaojing
@ -59,7 +59,7 @@ public class NacosDiscoveryClientConfiguration {
matchIfMissing = true) matchIfMissing = true)
public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager, public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager,
NacosDiscoveryProperties nacosDiscoveryProperties, NacosDiscoveryProperties nacosDiscoveryProperties,
ObjectProvider<TaskScheduler> taskExecutorObjectProvider) { ObjectProvider<ThreadPoolTaskScheduler> taskExecutorObjectProvider) {
return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties, return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties,
taskExecutorObjectProvider); taskExecutorObjectProvider);
} }

@ -27,7 +27,6 @@ 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.cloud.nacos.NacosServiceManager;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.Event; import com.alibaba.nacos.api.naming.listener.Event;
import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.listener.EventListener;
@ -41,7 +40,6 @@ 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; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/** /**
@ -66,14 +64,15 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
private final NacosDiscoveryProperties properties; private final NacosDiscoveryProperties properties;
private final TaskScheduler taskScheduler; private final ThreadPoolTaskScheduler taskScheduler;
public NacosWatch(NacosServiceManager nacosServiceManager, public NacosWatch(NacosServiceManager nacosServiceManager,
NacosDiscoveryProperties properties, NacosDiscoveryProperties properties,
ObjectProvider<TaskScheduler> taskScheduler) { ObjectProvider<ThreadPoolTaskScheduler> taskScheduler) {
this.nacosServiceManager = nacosServiceManager; this.nacosServiceManager = nacosServiceManager;
this.properties = properties; this.properties = properties;
this.taskScheduler = taskScheduler.getIfAvailable(NacosWatch::getTaskScheduler); this.taskScheduler = taskScheduler.stream().findAny()
.orElseGet(NacosWatch::getTaskScheduler);
} }
private static ThreadPoolTaskScheduler getTaskScheduler() { private static ThreadPoolTaskScheduler getTaskScheduler() {
@ -156,7 +155,7 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
if (this.watchFuture != null) { if (this.watchFuture != null) {
// shutdown current user-thread, // shutdown current user-thread,
// then the other daemon-threads will terminate automatic. // then the other daemon-threads will terminate automatic.
((ThreadPoolTaskScheduler) this.taskScheduler).shutdown(); this.taskScheduler.shutdown();
this.watchFuture.cancel(true); this.watchFuture.cancel(true);
} }
@ -167,7 +166,7 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl
namingService.unsubscribe(properties.getService(), properties.getGroup(), namingService.unsubscribe(properties.getService(), properties.getGroup(),
Arrays.asList(properties.getClusterName()), eventListener); Arrays.asList(properties.getClusterName()), eventListener);
} }
catch (NacosException e) { catch (Exception e) {
log.error("namingService unsubscribe failed, properties:{}", properties, log.error("namingService unsubscribe failed, properties:{}", properties,
e); e);
} }

@ -36,7 +36,7 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
* *
* @author xiaojing * @author xiaojing
*/ */
@Endpoint(id = "nacos-discovery") @Endpoint(id = "nacosdiscovery")
public class NacosDiscoveryEndpoint { public class NacosDiscoveryEndpoint {
private static final Logger log = LoggerFactory private static final Logger log = LoggerFactory

@ -36,6 +36,7 @@ import io.seata.core.context.RootContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
@ -156,11 +157,15 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
public K call() throws Exception { public K call() throws Exception {
try { try {
RequestContextHolder.setRequestAttributes(requestAttributes); RequestContextHolder.setRequestAttributes(requestAttributes);
if (!StringUtils.isEmpty(xid)) {
RootContext.bind(xid); RootContext.bind(xid);
}
return actual.call(); return actual.call();
} }
finally { finally {
if (!StringUtils.isEmpty(xid)) {
RootContext.unbind(); RootContext.unbind();
}
RequestContextHolder.resetRequestAttributes(); RequestContextHolder.resetRequestAttributes();
} }
} }

Loading…
Cancel
Save