springcloud微服务分布式事务处理方案-seata

本文只是记录整合阿里开源的分布式事务seata过程中的遇到的问题

seata版本:1.2.0

springcloud版本: Greenwich.SR3

一、下载seata服务端

地址:https://github.com/seata/seata/releases

按照官网安装步骤安装,如果采用db存储方式,需执行seata服务端脚本

https://github.com/seata/seata/tree/1.2.0/script/server/db

二、客户端整合seata

1、在各个服务的库里执行seata客户端的脚本,地址:https://github.com/seata/seata/tree/1.2.0/script/client/at/db

2、引入seata的配置文件,新版本支持yml文件替换registry.conf和file.conf的,我才用的是yml方式

# -----------seata--------------
seata:
  enabled: true
  application-id: ${spring.application.name}-seata #服务名
  tx-service-group: my_test_tx_group # my_test_tx_group是自定义的事务分组名称
  service:
    vgroup-mapping:
      my_test_tx_group: default # my_test_tx_group是自定义的事务分组名称
    grouplist:
      default: 192.168.100.16:8091 # 	仅注册中心为file时使用
    enable-degrade: false # 是否启用降级
    disable-global-transaction: false # 是否禁用全局事务
  config:
    type: file # 配置中心为file模式
  registry:
    type: eureka # 注册中心为eureka
    eureka:
      weight: 1
      service-url: http://192.168.100.16:8761/eureka # 注册中心地址

配置的详细信息请参考

https://github.com/seata/seata/tree/1.2.0/script/client/spring/application.yml

http://seata.io/zh-cn/docs/user/configurations.html

以上两个大步骤即可。

 

整合过程参考的文章如下:

http://seata.io/zh-cn/docs/overview/what-is-seata.html

https://github.com/lightClouds917/springcloud-eureka-feign-mybatis-seata-v100

http://www.iocoder.cn/Spring-Boot/Seata/?self

https://github.com/baomidou/dynamic-datasource-spring-boot-starter/wiki/Integration-With-Seata

备注:

1、引用的maven如下,如果jar包引用不对,导致引用的seata缺包,我是已这个版本成功的

<!--seata-->
		<dependency>
			<groupId>com.alibaba.cloud</groupId>
			<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
			<version>2.2.0.RELEASE</version>
			<exclusions>
				<exclusion>
					<groupId>io.seata</groupId>
					<artifactId>seata-spring-boot-starter</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>io.seata</groupId>
			<artifactId>seata-spring-boot-starter</artifactId>
			<version>1.2.0</version>
		</dependency>
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
			<version>3.0.0</version>
		</dependency>

2、被调用的service一定要加上 

@Transactional(propagation = Propagation.REQUIRES_NEW) // 开启新事物

并且propagation = Propagation.REQUIRES_NEW 必须填写

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值