Skip to content

Commit

Permalink
Merge pull request apache#39 from heshouyou/master
Browse files Browse the repository at this point in the history
add new module springboot-dubbo-fescar
  • Loading branch information
slievrly authored Feb 19, 2019
2 parents 603d1fb + 4ebc523 commit bfe8c72
Show file tree
Hide file tree
Showing 57 changed files with 2,412 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<module>dubbo</module>
<module>springboot</module>
<module>nacos</module>
<module>springboot-dubbo-fescar</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
71 changes: 71 additions & 0 deletions springboot-dubbo-fescar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 基于阿里Fescar分布式事务解决案例

一、什么是Fescar?

Fescar全称为:Fast Easy Commit And Rollback,是阿里巴巴公司基于TXC和GTS于2019年开源的微服务架构分布式事务解决方案。该方案基于java实现、简单易用、性能强悍、业务侵入低,是一款能够解决大多数分布式事务场景的极佳选择。原理解析请关注 : https://github.com/alibaba/fescar

二、原理浅析和场景展示

![FESCAR solution](https://camo.githubusercontent.com/b3a71332ae0a91db7f8616286a69b879fcbea672/68747470733a2f2f63646e2e6e6c61726b2e636f6d2f6c61726b2f302f323031382f706e672f31383836322f313534353239363739313037342d33626365376263652d303235652d343563332d393338362d3762393531333564616465382e706e67)

​ 该案例实现的微服务架构下的场景示例图



![Typical Process](https://camo.githubusercontent.com/0384806afd7c10544c258ae13717e4229942aa13/68747470733a2f2f63646e2e6e6c61726b2e636f6d2f6c61726b2f302f323031382f706e672f31383836322f313534353239363931373838312d32366661626562392d373166612d346633652d386137612d6663333137643333383966342e706e67)

​ Fescar原理图浅析



三、核心技术栈

* SpringBoot 2.0.8.RELEASE(2.0以后第一个GA版本)
* SpringCloud Finchley.SR2
* SpringCloudOpenFeigin
* Durid 1.1.10(阿里巴巴开源高性能数据源连接池)
* Mybatis 3.4.6(Mybatis-3)
* Dubbo 2.6.5(阿里巴巴开源高性能RPC框架)
* Fescar 0.2.1(阿里巴巴开源分布式事务解决方案,第二个小版本)
* Nacos 0.8.0(阿里巴巴开源注册中心/配置中心)

四、实现以及规划

* 当前版本实现SpringBoot + Dubbo + Mybatis + Nacos + Fescar技术整合,实现如何在微服务架构中使用分布式事务框架Fescar
* 之后版本将完善流程,并使用Nacos作为配置中心(现在Nacos只是作为注册中心)
* 接下来版本等到Fescar完善到0.5.0版本后开始支持SringCloud相关技术栈,将实现在Cloud微服务架构中解决分布式事务
* 计划暂定上述

五、使用该案例说明

1. 前往Fescar Github官方页面下载最新版本的 https://github.com/alibaba/fescar/releases

2. 前往Nacos Github官方页面下载最新版本的 https://github.com/alibaba/nacos/releases

3. clone此项目到本地,使用maven构建导入IDEA编辑器中,配置项目使用的maven仓库和JDK版本(1.8)

4. 将sql目录中的sql脚本导入到mysql数据库中,在此之前先创建数据库 db_gts_fescar,设置用户名密码为root root

5. 模块说明:

- samples-account 用户账户微服务模块
- samples-dubbo-business-call 业务发起方模块
- samples-common 项目公共架构模块
- samples-order 订单微服务模块
- samples-storage 库存微服务模块

6. 首先启动Nacos和Fescar,中间件具体使用说明详见上述Github官方页

7. 分别启动samples-account、samples-order、samples-storage、samples-dubbo-business-call四个模块,确定微服务都注册到Nacos和Fescar

8. 使用Postman工具请求Post接口地址:http://localhost:8104/business/dubbo/buy 模拟发起下单业务请求,成功后返回200

9. 接下来测试全局回滚功能,打开samples-dubbo-business-call模块下的 BusinessServiceImpl类,打开被注释的代码

```
if (!flag) {
throw new RuntimeException("测试抛异常后,分布式事务回滚!");
}
```

10. 再次请求测试发生异常后全局事务被回滚
139 changes: 139 additions & 0 deletions springboot-dubbo-fescar/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
~
~ 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
~
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-samples</artifactId>
<version>0.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>springboot-dubbo-fescar</artifactId>
<packaging>pom</packaging>
<name>fescar-samples-springboot-dubbo-nacos ${project.version}</name>
<modules>
<module>samples-common</module>
<module>samples-account</module>
<module>samples-order</module>
<module>samples-storage</module>
<module>samples-dubbo-business-call</module>
</modules>

<properties>
<java.version>1.8</java.version>
<fescar.version>0.2.1</fescar.version>
<druid.version>1.1.10</druid.version>
<mybatis.version>1.3.2</mybatis.version>
<mybatis-plus.version>2.3</mybatis-plus.version>
<dubbo-boot.version>0.2.1.RELEASE</dubbo-boot.version>
<nacos.version>0.2.1.RELEASE</nacos.version>
<springboot.version>2.0.8.RELEASE</springboot.version>
<nacos-config-spring-boot.version>0.2.1</nacos-config-spring-boot.version>
<dubbo-registry-nacos.version>0.0.2</dubbo-registry-nacos.version>
<lombok.version>1.16.22</lombok.version>
<spring.version>5.0.8.RELEASE</spring.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${springboot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springboot.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo-boot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${nacos.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-spring</artifactId>
<version>${fescar.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-dubbo-alibaba</artifactId>
<version>${fescar.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${dubbo-registry-nacos.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${nacos-config-spring-boot.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>

</dependencies>

</project>
101 changes: 101 additions & 0 deletions springboot-dubbo-fescar/samples-account/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
~
~ 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
~
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-dubbo-fescar</artifactId>
<groupId>com.alibaba.fescar</groupId>
<version>0.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>samples-account</artifactId>
<packaging>jar</packaging>
<name>samples-account ${project.version}</name>

<dependencies>
<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>samples-common</artifactId>
<version>${parent.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<artifactId>nacos-client</artifactId>
<groupId>com.alibaba.nacos</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-spring</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-dubbo-alibaba</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>nacos-client</artifactId>
<groupId>com.alibaba.nacos</groupId>
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.alibaba.fescar.samples.integration.account;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication(scanBasePackages = "com.alibaba.fescar.samples.integration.account")
@EnableDiscoveryClient
@MapperScan({"com.alibaba.fescar.samples.integration.account.mapper"})
@EnableDubbo(scanBasePackages = "com.alibaba.fescar.samples.integration.account")
public class AccountGtsFescarExampleApplication {

public static void main(String[] args) {
SpringApplication.run(AccountGtsFescarExampleApplication.class, args);
}

}

Loading

0 comments on commit bfe8c72

Please sign in to comment.