分布式事务2阶段提交理论的落地方案seata的项目实战演示
背景
看过我上一篇文章的小伙伴应该对seata 项目有了一个大概的认识,这一篇我就拿实际案例用户下订单->扣减库存->扣减用户余额,来演示。
前期准备
- 下载好seata-server 本示例以1.4.0版为例
- 业务系统: 订单系统 仓储系统 用户系统
- 所用框架 springboot , mybaits, httpclient
项目调用结构
实战
引入jar包,spring-cloud-alibaba 版
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency>
业务配置实例:
seata.enabled=true seata.application-id=mydemo seata.tx-service-group=my_test_tx_group seata.enable-auto-data-source-proxy=true seata.service.vgroup-mapping.my_test_tx_group=default seata.service.grouplist.default=localhost:8091
购买商品入口
订单创建方法