增加 dubbo x seata 分布式事务

This commit is contained in:
YunaiV
2020-04-05 22:16:45 +08:00
parent dd503c3e31
commit 80d478d2d0
6 changed files with 16 additions and 13 deletions

View File

@@ -236,6 +236,11 @@
**[Sentinel](http://www.iocoder.cn/Sentinel/install/?github)**
* [《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Dubbo/?github)的[「6. 整合 Sentinel」](#)小节
## 分布式事务
**[Seata](http://www.iocoder.cn/Seata/install/?github)**
* [《芋道 Dubbo 分布式事务 Seata 入门》](http://www.iocoder.cn/Dubbo/Seata/?self) 对应 [lab-53](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-53)
## 链路追踪
**[SkyWalking](http://www.iocoder.cn/SkyWalking/install/?github)**
@@ -283,8 +288,9 @@
## AT 方案
* [《芋道 Spring Boot 分布式事务 Seata 入门》](http://www.iocoder.cn/Spring-Boot/Seata/?self) 的[「2. AT 模式 + 多数据源」](#)小节,实现单体 Spring Boot 项目在多数据源下的分布式事务
* [《芋道 Spring Boot 分布式事务 Seata 入门》](http://www.iocoder.cn/Spring-Boot/Seata/?self) 的[「AT 模式 + HttpClient 远程调用」](#)小节,实现多个 Spring Boot 项目的分布事务
* [《芋道 Spring Boot 分布式事务 Seata 入门》](http://www.iocoder.cn/Spring-Boot/Seata/?self)的[「2. AT 模式 + 多数据源」](#)小节,实现单体 Spring Boot 项目在多数据源下的分布式事务
* [《芋道 Spring Boot 分布式事务 Seata 入门》](http://www.iocoder.cn/Spring-Boot/Seata/?self)的[「AT 模式 + HttpClient 远程调用」](#)小节,实现多个 Spring Boot 项目的分布事务
* [《芋道 Dubbo 分布式事务 Seata 入门》](http://www.iocoder.cn/Dubbo/Seata/?self) 的[「2. AT 模式」](#)小节,实现多个 Dubbo 服务的分布式事务。
## TCC 方案

View File

@@ -6,7 +6,6 @@ import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@org.apache.dubbo.config.annotation.Service
@@ -18,7 +17,7 @@ public class AccountServiceImpl implements AccountService {
private AccountDao accountDao;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW) // 开启新事物
@Transactional // 开启新事物
public void reduceBalance(Long userId, Integer price) throws Exception {
logger.info("[reduceBalance] 当前 XID: {}", RootContext.getXID());

View File

@@ -60,19 +60,19 @@
<version>1.1.0</version>
</dependency>
<!-- 实现对 Dubbo 的自动化配置 -->
<!-- 引入 Dubbo 的依赖 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.4.1</version>
</dependency>
<!-- 实现对 Dubbo 的自动化配置 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.4.1</version>
</dependency>
<!-- 使用 Nacos 作为注册中心 -->
<!-- 实现 Dubbo 使用 Nacos 作为注册中心 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-nacos</artifactId>

View File

@@ -22,7 +22,6 @@ public class OrderServiceImpl implements OrderService {
@Reference
private AccountService accountService;
@Reference
private ProductService productService;

View File

@@ -50,19 +50,19 @@
<version>1.1.0</version>
</dependency>
<!-- 实现对 Dubbo 的自动化配置 -->
<!-- 引入 Dubbo 的依赖 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.4.1</version>
</dependency>
<!-- 实现对 Dubbo 的自动化配置 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.4.1</version>
</dependency>
<!-- 使用 Nacos 作为注册中心 -->
<!-- 实现 Dubbo 使用 Nacos 作为注册中心 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-nacos</artifactId>

View File

@@ -6,7 +6,6 @@ import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@org.apache.dubbo.config.annotation.Service
@@ -18,7 +17,7 @@ public class ProductServiceImpl implements ProductService {
private ProductDao productDao;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW) // 开启新事物
@Transactional // 开启新事物
public void reduceStock(Long productId, Integer amount) throws Exception {
logger.info("[reduceStock] 当前 XID: {}", RootContext.getXID());