1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge pull request #5 from spring-cloud-incubator/master

merge
This commit is contained in:
Kai 2019-04-17 11:36:18 +08:00 committed by GitHub
commit 541d651fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
75 changed files with 623 additions and 346 deletions

View File

@ -62,7 +62,7 @@
<organization>Alibaba</organization>
<url>https://github.com/mercyblitz</url>
</developer>
<developer>
<developer>
<name>yunzheng</name>
<email>yunzheng1228@gmail.com</email>
</developer>
@ -96,7 +96,7 @@
<module>spring-cloud-alibaba-sentinel-zuul</module>
<module>spring-cloud-alibaba-nacos-config</module>
<module>spring-cloud-alibaba-nacos-discovery</module>
<module>spring-cloud-alibaba-fescar</module>
<module>spring-cloud-alibaba-seata</module>
<module>spring-cloud-stream-binder-rocketmq</module>
<module>spring-cloud-alibaba-nacos-config-server</module>
<module>spring-cloud-alibaba-dubbo</module>

View File

@ -63,7 +63,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-fescar</artifactId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
</dependencies>

View File

@ -17,10 +17,10 @@
<description>Spring Cloud Alibaba Dependencies</description>
<properties>
<sentinel.version>1.4.2</sentinel.version>
<sentinel.version>1.5.1</sentinel.version>
<oss.version>3.1.0</oss.version>
<fescar.version>0.4.0</fescar.version>
<nacos.client.version>1.0.0-RC3</nacos.client.version>
<fescar.version>0.4.2</fescar.version>
<nacos.client.version>1.0.0</nacos.client.version>
<nacos.config.version>0.8.0</nacos.config.version>
<acm.version>1.0.8</acm.version>
<ans.version>1.0.1</ans.version>
@ -29,8 +29,8 @@
<aliyun.sdk.edas.version>2.16.0</aliyun.sdk.edas.version>
<rocketmq.starter.version>2.0.2</rocketmq.starter.version>
<schedulerX.client.version>2.1.6</schedulerX.client.version>
<dubbo.version>2.6.5</dubbo.version>
<dubbo-spring-boot.version>0.2.1.RELEASE</dubbo-spring-boot.version>
<dubbo.version>2.7.1</dubbo.version>
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
<dubbo-registry-nacos.version>0.0.2</dubbo-registry-nacos.version>
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
<aliyun.sdk.mns>1.1.8</aliyun.sdk.mns>
@ -167,6 +167,11 @@
<artifactId>sentinel-dubbo-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
@ -194,7 +199,7 @@
<!-- Dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<exclusions>
@ -215,7 +220,7 @@
<!-- Dubbo Spring Boot Starter -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo-spring-boot.version}</version>
</dependency>
@ -272,7 +277,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-fescar</artifactId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -325,7 +330,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>${project.version}</version>
</dependency>

View File

@ -18,7 +18,6 @@ package org.springframework.cloud.alibaba.dubbo.autoconfigure;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
import com.ecwid.consul.v1.agent.model.NewService;
import org.aspectj.lang.ProceedingJoinPoint;
@ -30,6 +29,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceMetadataRepository;
import org.springframework.cloud.alibaba.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.serviceregistry.Registration;
@ -40,7 +41,7 @@ import org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegist
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import java.util.List;
import java.util.Collection;
import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_CONFIGURATION_CLASS_NAME;
import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.ZOOKEEPER_AUTO_CONFIGURATION_CLASS_NAME;
@ -65,18 +66,21 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
@Autowired
private Registration registration;
private volatile Integer webPort = null;
private volatile Integer serverPort = null;
private volatile boolean registered = false;
@Autowired
private DubboServiceMetadataRepository repository;
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
return webPort != null ? webPort : pjp.proceed();
return serverPort != null ? serverPort : pjp.proceed();
}
@EventListener(ServiceBeanExportedEvent.class)
public void onServiceBeanExported(ServiceBeanExportedEvent event) {
setWebPort(event.getServiceBean());
@EventListener(ApplicationStartedEvent.class)
public void onApplicationStarted() {
setServerPort();
register();
}
@ -90,18 +94,24 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
/**
* Set web port from {@link ServiceBean#getExportedUrls() exported URLs} if "rest" protocol is present.
*
* @param serviceBean {@link ServiceBean}
*/
private void setWebPort(ServiceBean serviceBean) {
if (webPort == null) {
List<URL> urls = serviceBean.getExportedUrls();
private void setServerPort() {
if (serverPort == null) {
Collection<URL> urls = repository.getRegisteredUrls();
urls.stream()
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
.findFirst()
.ifPresent(url -> {
webPort = url.getPort();
serverPort = url.getPort();
});
// If REST protocol is not present, use any applied port.
if (serverPort == null) {
urls.stream()
.findAny().ifPresent(url -> {
serverPort = url.getPort();
});
}
}
}
@ -114,7 +124,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
@EventListener(ServiceInstancePreRegisteredEvent.class)
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
registration.setPort(webPort);
registration.setPort(serverPort);
}
@Override

View File

@ -37,6 +37,7 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.Collection;
@ -260,8 +261,10 @@ public class DubboServiceMetadataRepository {
Set<ServiceRestMetadata> metadata = Collections.emptySet();
try {
String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
if(StringUtils.hasText(serviceRestMetadataJsonConfig)) {
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);

View File

@ -1,35 +0,0 @@
registry {
# file 、nacos 、redis
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
file {
name = "file.conf"
}
}
config {
# file nacos apollo
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
file {
name = "file.conf"
}
}

View File

@ -1,35 +0,0 @@
registry {
# file 、nacos 、redis
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
file {
name = "file.conf"
}
}
config {
# file nacos apollo
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
file {
name = "file.conf"
}
}

View File

@ -1,35 +0,0 @@
registry {
# file 、nacos 、redis
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
file {
name = "file.conf"
}
}
config {
# file nacos apollo
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
file {
name = "file.conf"
}
}

View File

@ -1,35 +0,0 @@
registry {
# file 、nacos 、redis
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
file {
name = "file.conf"
}
}
config {
# file nacos apollo
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
file {
name = "file.conf"
}
}

View File

@ -28,10 +28,10 @@
<module>ans-example/ans-consumer-feign-example</module>
<module>ans-example/ans-consumer-ribbon-example</module>
<module>ans-example/ans-provider-example</module>
<module>fescar-example/business-service</module>
<module>fescar-example/order-service</module>
<module>fescar-example/storage-service</module>
<module>fescar-example/account-service</module>
<module>seata-example/business-service</module>
<module>seata-example/order-service</module>
<module>seata-example/storage-service</module>
<module>seata-example/account-service</module>
<module>acm-example/acm-local-example</module>
<module>rocketmq-example/rocketmq-consume-example</module>
<module>rocketmq-example/rocketmq-produce-example</module>

View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -20,17 +20,26 @@ transport {
worker-thread-size = 8
}
}
store {
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
max-branch-session-size = 16384
# globe session size , if exceeded throws exceptions
max-global-session-size = 512
# file buffer size , if exceeded allocate new buffer
file-write-buffer-cache-size = 16384
# when recover batch read size
session.reload.read_size = 100
}
service {
#vgroup->rgroup
vgroup_mapping.account-service-fescar-service-group = "localRgroup"
vgroup_mapping.account-service-fescar-service-group = "default"
#only support single node
localRgroup.grouplist = "127.0.0.1:8091"
default.grouplist = "127.0.0.1:8091"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
client {
async.commit.buffer.limit = 10000
lock {

View File

@ -0,0 +1,55 @@
registry {
# file 、nacos 、eureka、redis、zk、consul
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:1001/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
file {
name = "file.conf"
}
}

View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@ -20,17 +20,26 @@ transport {
worker-thread-size = 8
}
}
store {
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
max-branch-session-size = 16384
# globe session size , if exceeded throws exceptions
max-global-session-size = 512
# file buffer size , if exceeded allocate new buffer
file-write-buffer-cache-size = 16384
# when recover batch read size
session.reload.read_size = 100
}
service {
#vgroup->rgroup
vgroup_mapping.storage-service-fescar-service-group = "localRgroup"
vgroup_mapping.business-service-fescar-service-group = "default"
#only support single node
localRgroup.grouplist = "127.0.0.1:8091"
default.grouplist = "127.0.0.1:8091"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
client {
async.commit.buffer.limit = 10000
lock {

View File

@ -0,0 +1,55 @@
registry {
# file 、nacos 、eureka、redis、zk、consul
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:1001/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
file {
name = "file.conf"
}
}

View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -20,17 +20,26 @@ transport {
worker-thread-size = 8
}
}
store {
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
max-branch-session-size = 16384
# globe session size , if exceeded throws exceptions
max-global-session-size = 512
# file buffer size , if exceeded allocate new buffer
file-write-buffer-cache-size = 16384
# when recover batch read size
session.reload.read_size = 100
}
service {
#vgroup->rgroup
vgroup_mapping.business-service-fescar-service-group = "localRgroup"
vgroup_mapping.order-service-fescar-service-group = "default"
#only support single node
localRgroup.grouplist = "127.0.0.1:8091"
default.grouplist = "127.0.0.1:8091"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
client {
async.commit.buffer.limit = 10000
lock {

View File

@ -0,0 +1,55 @@
registry {
# file 、nacos 、eureka、redis、zk、consul
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:1001/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
file {
name = "file.conf"
}
}

View File

@ -1,11 +1,11 @@
# Fescar Example
# Seata Example
## 项目说明
本项目演示如何使用 Fescar Starter 完成 Spring Cloud 应用的分布式事务接入。
本项目演示如何使用 Seata Starter 完成 Spring Cloud 应用的分布式事务接入。
[Fescar](https://github.com/alibaba/fescar) 是 阿里巴巴 开源的 分布式事务中间件,以 高效 并且对业务 0 侵入 的方式,解决 微服务 场景下面临的分布式事务问题。
[Seata](https://github.com/seata/seata) 是 阿里巴巴 开源的 分布式事务中间件,以 高效 并且对业务 0 侵入 的方式,解决 微服务 场景下面临的分布式事务问题。

View File

@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -20,17 +20,26 @@ transport {
worker-thread-size = 8
}
}
store {
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
max-branch-session-size = 16384
# globe session size , if exceeded throws exceptions
max-global-session-size = 512
# file buffer size , if exceeded allocate new buffer
file-write-buffer-cache-size = 16384
# when recover batch read size
session.reload.read_size = 100
}
service {
#vgroup->rgroup
vgroup_mapping.order-service-fescar-service-group = "localRgroup"
vgroup_mapping.storage-service-fescar-service-group = "default"
#only support single node
localRgroup.grouplist = "127.0.0.1:8091"
default.grouplist = "127.0.0.1:8091"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
client {
async.commit.buffer.limit = 10000
lock {

View File

@ -0,0 +1,55 @@
registry {
# file 、nacos 、eureka、redis、zk、consul
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:1001/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk
type = "file"
nacos {
serverAddr = "localhost"
namespace = "public"
cluster = "default"
}
apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
file {
name = "file.conf"
}
}

View File

@ -28,12 +28,17 @@
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</dependency>

View File

@ -1,14 +1,13 @@
package org.springframework.cloud.alibaba.cloud.examples;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Reference;
/**
* @author fangjian
*/
public class FooServiceConsumer {
@Reference(version = "${foo.service.version}", application = "${dubbo.application.id}",
url = "dubbo://localhost:12345", timeout = 30000)
@Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345", timeout = 30000)
private FooService fooService;
public String hello(String name) {

View File

@ -21,18 +21,24 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</dependency>

View File

@ -1,20 +1,15 @@
package org.springframework.cloud.alibaba.cloud.examples;
import com.alibaba.dubbo.config.annotation.Service;
import org.apache.dubbo.config.annotation.Service;
/**
* @author fangjian
*/
@Service(
version = "${foo.service.version}",
application = "${dubbo.application.id}",
protocol = "${dubbo.protocol.id}",
registry = "${dubbo.registry.id}"
)
@Service(version = "${foo.service.version}", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}")
public class FooServiceImpl implements FooService {
@Override
public String hello(String name) {
return "hello, " + name;
}
@Override
public String hello(String name) {
return "hello, " + name;
}
}

View File

@ -26,6 +26,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.alibaba.dubbo.annotation.DubboTransported;
import org.springframework.cloud.alibaba.dubbo.service.RestService;
import org.springframework.cloud.alibaba.dubbo.service.User;
import org.springframework.cloud.alibaba.dubbo.service.UserService;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
@ -53,6 +54,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
@EnableFeignClients
public class DubboSpringCloudConsumerBootstrap {
@Reference
private UserService userService;
@Reference(version = "1.0.0", protocol = "dubbo")
private RestService restService;
@ -119,7 +123,28 @@ public class DubboSpringCloudConsumerBootstrap {
}
@Bean
public ApplicationRunner paramRunner() {
public ApplicationRunner userServiceRunner() {
return arguments -> {
User user = new User();
user.setId(1L);
user.setName("小马哥");
user.setAge(33);
// save User
System.out.printf("UserService.save(%s) : %s\n", user, userService.save(user));
// find all Users
System.out.printf("UserService.findAll() : %s\n", user, userService.findAll());
// remove User
System.out.printf("UserService.remove(%d) : %s\n", user.getId(), userService.remove(user.getId()));
};
}
@Bean
public ApplicationRunner callRunner() {
return arguments -> {
// To call /path-variables

View File

@ -0,0 +1,47 @@
/*
* 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 org.springframework.cloud.alibaba.dubbo.service;
import org.apache.dubbo.config.annotation.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* In-Memory {@link UserService} implementation
*/
@Service(protocol = "dubbo")
public class InMemoryUserService implements UserService {
private Map<Long, User> usersRepository = new HashMap<>();
@Override
public boolean save(User user) {
return usersRepository.put(user.getId(), user) == null;
}
@Override
public boolean remove(Long userId) {
return usersRepository.remove(userId) != null;
}
@Override
public Collection<User> findAll() {
return usersRepository.values();
}
}

View File

@ -0,0 +1,47 @@
/*
* 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 org.springframework.cloud.alibaba.dubbo.service;
import org.apache.dubbo.config.annotation.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* In-Memory {@link UserService} implementation
*/
@Service(protocol = "dubbo")
public class InMemoryUserService implements UserService {
private Map<Long, User> usersRepository = new HashMap<>();
@Override
public boolean save(User user) {
return usersRepository.put(user.getId(), user) == null;
}
@Override
public boolean remove(Long userId) {
return usersRepository.remove(userId) != null;
}
@Override
public Collection<User> findAll() {
return usersRepository.values();
}
}

View File

@ -0,0 +1,33 @@
/*
* 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 org.springframework.cloud.alibaba.dubbo.service;
import java.util.Collection;
/**
* {@link User} Service
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
public interface UserService {
boolean save(User user);
boolean remove(Long userId);
Collection<User> findAll();
}

View File

@ -1,7 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.fescar.rest.FescarRestTemplateAutoConfiguration,\
org.springframework.cloud.alibaba.fescar.web.FescarHandlerInterceptorConfiguration,\
org.springframework.cloud.alibaba.fescar.GlobalTransactionAutoConfiguration,\
org.springframework.cloud.alibaba.fescar.feign.FescarFeignClientAutoConfiguration,\
org.springframework.cloud.alibaba.fescar.feign.hystrix.FescarHystrixAutoConfiguration

View File

@ -57,14 +57,10 @@ import org.springframework.test.context.junit4.SpringRunner;
"spring.cloud.nacos.config.encode=utf-8",
"spring.cloud.nacos.config.timeout=1000",
"spring.cloud.nacos.config.file-extension=properties",
"spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties",
"spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties",
"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP",
"spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
"spring.cloud.nacos.config.accessKey=test-accessKey",
"spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE)
public class NacosConfigurationExtConfigTests {

View File

@ -22,11 +22,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;
import com.alibaba.nacos.client.config.NacosConfigService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -48,6 +45,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.nacos.client.config.NacosConfigService;
/**
* @author xiaojing
*/
@ -59,7 +58,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = NacosConfigurationTests.TestConfig.class, properties = {
"spring.application.name=myTestService1", "spring.profiles.active=dev,test",
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
"spring.cloud.nacos.config.endpoint=test-endpoint",
"spring.cloud.nacos.config.namespace=test-namespace",
"spring.cloud.nacos.config.encode=utf-8",
"spring.cloud.nacos.config.timeout=1000",
@ -68,14 +66,10 @@ import org.springframework.test.context.junit4.SpringRunner;
"spring.cloud.nacos.config.cluster-name=test-cluster",
"spring.cloud.nacos.config.file-extension=properties",
"spring.cloud.nacos.config.contextPath=test-contextpath",
"spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties",
"spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties",
"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP",
"spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
"spring.cloud.nacos.config.accessKey=test-accessKey",
"spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE)
public class NacosConfigurationTests {
@ -83,8 +77,6 @@ public class NacosConfigurationTests {
static {
try {
// when(any(ConfigService.class).getConfig(eq("test-name.properties"),
// eq("test-group"), any())).thenReturn("user.name=hello");
Method method = PowerMockito.method(NacosConfigService.class, "getConfig",
String.class, String.class, long.class);
@ -152,7 +144,6 @@ public class NacosConfigurationTests {
assertNotNull("NacosConfigProperties was not created", properties);
checkoutNacosConfigServerAddr();
checkoutNacosConfigEndpoint();
checkoutNacosConfigNamespace();
checkoutNacosConfigClusterName();
checkoutNacosConfigAccessKey();
@ -172,19 +163,12 @@ public class NacosConfigurationTests {
private void checkoutNacosConfigServerAddr() {
assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
properties.getServerAddr());
}
private void checkoutNacosConfigEndpoint() {
assertEquals("NacosConfigProperties endpoint is wrong", "test-endpoint",
properties.getEndpoint());
}
private void checkoutNacosConfigNamespace() {
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
properties.getNamespace());
}
private void checkoutNacosConfigClusterName() {
@ -234,8 +218,8 @@ public class NacosConfigurationTests {
private void checkoutDataLoad() {
Assert.assertEquals(environment.getProperty("user.name"), "dev");
Assert.assertEquals(environment.getProperty("user.age"), "12");
Assert.assertEquals("dev", environment.getProperty("user.name"));
Assert.assertEquals("12", environment.getProperty("user.age"));
}
private void checkoutEndpoint() throws Exception {

View File

@ -10,8 +10,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-fescar</artifactId>
<name>Spring Cloud Alibaba Fescar</name>
<artifactId>spring-cloud-alibaba-seata</artifactId>
<name>Spring Cloud Alibaba Seata</name>
<dependencies>

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar;
package org.springframework.cloud.alibaba.seata;
import com.alibaba.fescar.spring.annotation.GlobalTransactionScanner;
@ -29,17 +29,17 @@ import org.springframework.util.StringUtils;
*/
@Configuration
@EnableConfigurationProperties(FescarProperties.class)
@EnableConfigurationProperties(SeataProperties.class)
public class GlobalTransactionAutoConfiguration {
private final ApplicationContext applicationContext;
private final FescarProperties fescarProperties;
private final SeataProperties seataProperties;
public GlobalTransactionAutoConfiguration(ApplicationContext applicationContext,
FescarProperties fescarProperties) {
SeataProperties seataProperties) {
this.applicationContext = applicationContext;
this.fescarProperties = fescarProperties;
this.seataProperties = seataProperties;
}
@Bean
@ -48,11 +48,11 @@ public class GlobalTransactionAutoConfiguration {
String applicationName = applicationContext.getEnvironment()
.getProperty("spring.application.name");
String txServiceGroup = fescarProperties.getTxServiceGroup();
String txServiceGroup = seataProperties.getTxServiceGroup();
if (StringUtils.isEmpty(txServiceGroup)) {
txServiceGroup = applicationName + "-fescar-service-group";
fescarProperties.setTxServiceGroup(txServiceGroup);
seataProperties.setTxServiceGroup(txServiceGroup);
}
return new GlobalTransactionScanner(applicationName, txServiceGroup);

View File

@ -14,20 +14,20 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar;
package org.springframework.cloud.alibaba.seata;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author xiaojing
*/
@ConfigurationProperties("spring.cloud.alibaba.fescar")
public class FescarProperties {
@ConfigurationProperties("spring.cloud.alibaba.seata")
public class SeataProperties {
// todo support config Fescar server information
/**
* Fescar tx service group.default is ${spring.application.name}-fescar-service-group.
* Seata tx service group.default is ${spring.application.name}-fescar-service-group.
*/
private String txServiceGroup;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
@ -22,18 +22,18 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* @author xiaojing
*/
final class FescarBeanPostProcessor implements BeanPostProcessor {
final class SeataBeanPostProcessor implements BeanPostProcessor {
private final FescarFeignObjectWrapper fescarFeignObjectWrapper;
private final SeataFeignObjectWrapper seataFeignObjectWrapper;
FescarBeanPostProcessor(FescarFeignObjectWrapper fescarFeignObjectWrapper) {
this.fescarFeignObjectWrapper = fescarFeignObjectWrapper;
SeataBeanPostProcessor(SeataFeignObjectWrapper seataFeignObjectWrapper) {
this.seataFeignObjectWrapper = seataFeignObjectWrapper;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return this.fescarFeignObjectWrapper.wrap(bean);
return this.seataFeignObjectWrapper.wrap(bean);
}
@Override

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@ -24,20 +24,20 @@ import org.springframework.cloud.openfeign.FeignContext;
/**
* @author xiaojing
*/
public class FescarContextBeanPostProcessor implements BeanPostProcessor {
public class SeataContextBeanPostProcessor implements BeanPostProcessor {
private final BeanFactory beanFactory;
private FescarFeignObjectWrapper fescarFeignObjectWrapper;
private SeataFeignObjectWrapper seataFeignObjectWrapper;
FescarContextBeanPostProcessor(BeanFactory beanFactory) {
SeataContextBeanPostProcessor(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof FeignContext && !(bean instanceof FescarFeignContext)) {
return new FescarFeignContext(getFescarFeignObjectWrapper(),
if (bean instanceof FeignContext && !(bean instanceof SeataFeignContext)) {
return new SeataFeignContext(getSeataFeignObjectWrapper(),
(FeignContext) bean);
}
return bean;
@ -49,11 +49,11 @@ public class FescarContextBeanPostProcessor implements BeanPostProcessor {
return bean;
}
private FescarFeignObjectWrapper getFescarFeignObjectWrapper() {
if (this.fescarFeignObjectWrapper == null) {
this.fescarFeignObjectWrapper = this.beanFactory
.getBean(FescarFeignObjectWrapper.class);
private SeataFeignObjectWrapper getSeataFeignObjectWrapper() {
if (this.seataFeignObjectWrapper == null) {
this.seataFeignObjectWrapper = this.beanFactory
.getBean(SeataFeignObjectWrapper.class);
}
return this.fescarFeignObjectWrapper;
return this.seataFeignObjectWrapper;
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.factory.BeanFactory;
@ -23,12 +23,12 @@ import feign.Feign;
/**
* @author xiaojing
*/
final class FescarFeignBuilder {
final class SeataFeignBuilder {
private FescarFeignBuilder() {
private SeataFeignBuilder() {
}
static Feign.Builder builder(BeanFactory beanFactory) {
return Feign.builder().client(new FescarFeignClient(beanFactory));
return Feign.builder().client(new SeataFeignClient(beanFactory));
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import java.io.IOException;
import java.util.ArrayList;
@ -35,17 +35,17 @@ import org.springframework.util.StringUtils;
/**
* @author xiaojing
*/
public class FescarFeignClient implements Client {
public class SeataFeignClient implements Client {
private final Client delegate;
private final BeanFactory beanFactory;
FescarFeignClient(BeanFactory beanFactory) {
SeataFeignClient(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
this.delegate = new Client.Default(null, null);
}
FescarFeignClient(BeanFactory beanFactory, Client delegate) {
SeataFeignClient(BeanFactory beanFactory, Client delegate) {
this.delegate = delegate;
this.beanFactory = beanFactory;
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@ -36,14 +36,14 @@ import feign.Feign;
@Configuration
@ConditionalOnClass(Client.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)
public class FescarFeignClientAutoConfiguration {
public class SeataFeignClientAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand")
@ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true")
Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) {
return FescarHystrixFeignBuilder.builder(beanFactory);
return SeataHystrixFeignBuilder.builder(beanFactory);
}
@Bean
@ -51,34 +51,34 @@ public class FescarFeignClientAutoConfiguration {
@ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU")
@ConditionalOnProperty(name = "feign.sentinel.enabled", havingValue = "true")
Feign.Builder feignSentinelBuilder(BeanFactory beanFactory) {
return FescarSentinelFeignBuilder.builder(beanFactory);
return SeataSentinelFeignBuilder.builder(beanFactory);
}
@Bean
@ConditionalOnMissingBean
@Scope("prototype")
Feign.Builder feignBuilder(BeanFactory beanFactory) {
return FescarFeignBuilder.builder(beanFactory);
return SeataFeignBuilder.builder(beanFactory);
}
@Configuration
protected static class FeignBeanPostProcessorConfiguration {
@Bean
FescarBeanPostProcessor fescarBeanPostProcessor(
FescarFeignObjectWrapper fescarFeignObjectWrapper) {
return new FescarBeanPostProcessor(fescarFeignObjectWrapper);
SeataBeanPostProcessor fescarBeanPostProcessor(
SeataFeignObjectWrapper seataFeignObjectWrapper) {
return new SeataBeanPostProcessor(seataFeignObjectWrapper);
}
@Bean
FescarContextBeanPostProcessor fescarContextBeanPostProcessor(
SeataContextBeanPostProcessor fescarContextBeanPostProcessor(
BeanFactory beanFactory) {
return new FescarContextBeanPostProcessor(beanFactory);
return new SeataContextBeanPostProcessor(beanFactory);
}
@Bean
FescarFeignObjectWrapper fescarFeignObjectWrapper(BeanFactory beanFactory) {
return new FescarFeignObjectWrapper(beanFactory);
SeataFeignObjectWrapper fescarFeignObjectWrapper(BeanFactory beanFactory) {
return new SeataFeignObjectWrapper(beanFactory);
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import java.util.HashMap;
import java.util.Map;
@ -26,14 +26,14 @@ import org.springframework.cloud.openfeign.FeignContext;
*
* @author xiaojing
*/
public class FescarFeignContext extends FeignContext {
public class SeataFeignContext extends FeignContext {
private final FescarFeignObjectWrapper fescarFeignObjectWrapper;
private final SeataFeignObjectWrapper seataFeignObjectWrapper;
private final FeignContext delegate;
FescarFeignContext(FescarFeignObjectWrapper fescarFeignObjectWrapper,
FeignContext delegate) {
this.fescarFeignObjectWrapper = fescarFeignObjectWrapper;
SeataFeignContext(SeataFeignObjectWrapper seataFeignObjectWrapper,
FeignContext delegate) {
this.seataFeignObjectWrapper = seataFeignObjectWrapper;
this.delegate = delegate;
}
@ -43,7 +43,7 @@ public class FescarFeignContext extends FeignContext {
if (object instanceof Client) {
return object;
}
return (T) this.fescarFeignObjectWrapper.wrap(object);
return (T) this.seataFeignObjectWrapper.wrap(object);
}
@Override
@ -59,7 +59,7 @@ public class FescarFeignContext extends FeignContext {
}
else {
convertedInstances.put(entry.getKey(),
(T) this.fescarFeignObjectWrapper.wrap(entry.getValue()));
(T) this.seataFeignObjectWrapper.wrap(entry.getValue()));
}
}
return convertedInstances;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
@ -26,25 +26,25 @@ import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
/**
* @author xiaojing
*/
public class FescarFeignObjectWrapper {
public class SeataFeignObjectWrapper {
private final BeanFactory beanFactory;
private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory;
private SpringClientFactory springClientFactory;
FescarFeignObjectWrapper(BeanFactory beanFactory) {
SeataFeignObjectWrapper(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
Object wrap(Object bean) {
if (bean instanceof Client && !(bean instanceof FescarFeignClient)) {
if (bean instanceof Client && !(bean instanceof SeataFeignClient)) {
if (bean instanceof LoadBalancerFeignClient) {
LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean);
return new FescarLoadBalancerFeignClient(client.getDelegate(), factory(),
return new SeataLoadBalancerFeignClient(client.getDelegate(), factory(),
clientFactory(), this.beanFactory);
}
return new FescarFeignClient(this.beanFactory, (Client) bean);
return new SeataFeignClient(this.beanFactory, (Client) bean);
}
return bean;
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import feign.Retryer;
import feign.hystrix.HystrixFeign;
@ -25,13 +25,13 @@ import feign.Feign;
/**
* @author xiaojing
*/
final class FescarHystrixFeignBuilder {
final class SeataHystrixFeignBuilder {
private FescarHystrixFeignBuilder() {
private SeataHystrixFeignBuilder() {
}
static Feign.Builder builder(BeanFactory beanFactory) {
return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY)
.client(new FescarFeignClient(beanFactory));
.client(new SeataFeignClient(beanFactory));
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import java.io.IOException;
@ -30,13 +30,13 @@ import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
/**
* @author xiaojing
*/
public class FescarLoadBalancerFeignClient extends LoadBalancerFeignClient {
public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient {
private final BeanFactory beanFactory;
FescarLoadBalancerFeignClient(Client delegate,
CachingSpringLoadBalancerFactory lbClientFactory,
SpringClientFactory clientFactory, BeanFactory beanFactory) {
SeataLoadBalancerFeignClient(Client delegate,
CachingSpringLoadBalancerFactory lbClientFactory,
SpringClientFactory clientFactory, BeanFactory beanFactory) {
super(wrap(delegate, beanFactory), lbClientFactory, clientFactory);
this.beanFactory = beanFactory;
}
@ -47,7 +47,7 @@ public class FescarLoadBalancerFeignClient extends LoadBalancerFeignClient {
}
private static Client wrap(Client delegate, BeanFactory beanFactory) {
return (Client) new FescarFeignObjectWrapper(beanFactory).wrap(delegate);
return (Client) new SeataFeignObjectWrapper(beanFactory).wrap(delegate);
}
}

View File

@ -14,26 +14,24 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign;
package org.springframework.cloud.alibaba.seata.feign;
import org.springframework.beans.factory.BeanFactory;
import feign.Feign;
import feign.Retryer;
import feign.hystrix.HystrixFeign;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel;
import org.springframework.cloud.alibaba.sentinel.feign.SentinelFeign;
/**
* @author xiaojing
*/
final class FescarSentinelFeignBuilder {
final class SeataSentinelFeignBuilder {
private FescarSentinelFeignBuilder() {
private SeataSentinelFeignBuilder() {
}
static Feign.Builder builder(BeanFactory beanFactory) {
return SentinelFeign.builder().retryer(Retryer.NEVER_RETRY)
.client(new FescarFeignClient(beanFactory));
.client(new SeataFeignClient(beanFactory));
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign.hystrix;
package org.springframework.cloud.alibaba.seata.feign.hystrix;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
@ -27,11 +27,11 @@ import com.netflix.hystrix.HystrixCommand;
@Configuration
@ConditionalOnClass(HystrixCommand.class)
public class FescarHystrixAutoConfiguration {
public class SeataHystrixAutoConfiguration {
@Bean
FescarHystrixConcurrencyStrategy fescarHystrixConcurrencyStrategy() {
return new FescarHystrixConcurrencyStrategy();
SeataHystrixConcurrencyStrategy fescarHystrixConcurrencyStrategy() {
return new SeataHystrixConcurrencyStrategy();
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.feign.hystrix;
package org.springframework.cloud.alibaba.seata.feign.hystrix;
import java.util.concurrent.Callable;
@ -25,11 +25,11 @@ import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
/**
* @author xiaojing
*/
public class FescarHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
private HystrixConcurrencyStrategy delegate;
public FescarHystrixConcurrencyStrategy() {
public SeataHystrixConcurrencyStrategy() {
this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
HystrixPlugins.reset();
HystrixPlugins.getInstance().registerConcurrencyStrategy(this);

View File

@ -29,7 +29,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.rest;
package org.springframework.cloud.alibaba.seata.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@ -47,18 +47,18 @@ import java.util.List;
*/
@Configuration
public class FescarRestTemplateAutoConfiguration {
public class SeataRestTemplateAutoConfiguration {
@Bean
public FescarRestTemplateInterceptor fescarRestTemplateInterceptor() {
return new FescarRestTemplateInterceptor();
public SeataRestTemplateInterceptor fescarRestTemplateInterceptor() {
return new SeataRestTemplateInterceptor();
}
@Autowired(required = false)
private Collection<RestTemplate> restTemplates;
@Autowired
private FescarRestTemplateInterceptor fescarRestTemplateInterceptor;
private SeataRestTemplateInterceptor seataRestTemplateInterceptor;
@PostConstruct
public void init() {
@ -66,7 +66,7 @@ public class FescarRestTemplateAutoConfiguration {
for (RestTemplate restTemplate : restTemplates) {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>(
restTemplate.getInterceptors());
interceptors.add(this.fescarRestTemplateInterceptor);
interceptors.add(this.seataRestTemplateInterceptor);
restTemplate.setInterceptors(interceptors);
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.rest;
package org.springframework.cloud.alibaba.seata.rest;
import java.io.IOException;
@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
/**
* @author xiaojing
*/
public class FescarRestTemplateInterceptor implements ClientHttpRequestInterceptor {
public class SeataRestTemplateInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.web;
package org.springframework.cloud.alibaba.seata.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -35,10 +35,10 @@ import org.springframework.web.servlet.HandlerInterceptor;
* And clean up Fescar information after servlet method invocation in
* {@link org.springframework.web.servlet.HandlerInterceptor#afterCompletion(HttpServletRequest, HttpServletResponse, Object, Exception)}
*/
public class FescarHandlerInterceptor implements HandlerInterceptor {
public class SeataHandlerInterceptor implements HandlerInterceptor {
private static final Logger log = LoggerFactory
.getLogger(FescarHandlerInterceptor.class);
.getLogger(SeataHandlerInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.fescar.web;
package org.springframework.cloud.alibaba.seata.web;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ -22,10 +22,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author xiaojing
*/
public class FescarHandlerInterceptorConfiguration implements WebMvcConfigurer {
public class SeataHandlerInterceptorConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new FescarHandlerInterceptor()).addPathPatterns("/**");
registry.addInterceptor(new SeataHandlerInterceptor()).addPathPatterns("/**");
}
}

View File

@ -0,0 +1,7 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.seata.rest.SeataRestTemplateAutoConfiguration,\
org.springframework.cloud.alibaba.seata.web.SeataHandlerInterceptorConfiguration,\
org.springframework.cloud.alibaba.seata.GlobalTransactionAutoConfiguration,\
org.springframework.cloud.alibaba.seata.feign.SeataFeignClientAutoConfiguration,\
org.springframework.cloud.alibaba.seata.feign.hystrix.SeataHystrixAutoConfiguration

View File

@ -33,6 +33,13 @@
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-dubbo-adapter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<optional>true</optional>
</dependency>
<dependency>

View File

@ -174,6 +174,7 @@ public class SentinelAutoConfiguration {
return new SentinelDataSourceHandler(beanFactory);
}
@ConditionalOnClass(ObjectMapper.class)
protected static class SentinelConverterConfiguration {
private ObjectMapper objectMapper = new ObjectMapper();

View File

@ -16,7 +16,7 @@
<module>spring-cloud-starter-alibaba-nacos-config-server</module>
<module>spring-cloud-starter-alibaba-nacos-discovery</module>
<module>spring-cloud-starter-alibaba-sentinel</module>
<module>spring-cloud-starter-alibaba-fescar</module>
<module>spring-cloud-starter-alibaba-seata</module>
<module>spring-cloud-starter-stream-rocketmq</module>
<module>spring-cloud-starter-bus-rocketmq</module>
<module>spring-cloud-starter-dubbo</module>

View File

@ -7,13 +7,13 @@
<artifactId>spring-cloud-starter-alibaba</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-cloud-starter-alibaba-fescar</artifactId>
<name>Spring Cloud Starter Alibaba Fescar</name>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<name>Spring Cloud Starter Alibaba Seata</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-fescar</artifactId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
</dependency>
</dependencies>