分布式事务(五)Seata AT模式-Spring Cloud微服务添加 AT 分布式事务

分布式事务Seata AT模式结构图

在这里插入图片描述

seata server AT事务

部署Seata server (TC事务协调器)
1.下载seata server-1.3.zip
2.修改三个配置文件
  • registry.conf–向注册中心注册
    在这里插入图片描述

  • file.conf–协调运行过程中记录的日志数据,要存到数据库,所以要配置数据库
    在这里插入图片描述

  • seata-server.bat–配置 使用的内存(默认2G)该小(256M)–windows批处理文件
    在这里插入图片描述

3.执行seata-server.ba启动

只能是jdk1.8才能起来
在这里插入图片描述
seata-server.bat 回车
出现204
在这里插入图片描述
注册中心出现
在这里插入图片描述

注意事项

1.不能关闭小黑窗口
2.不能选中,如果选中,窗口中的应用会挂起(暂停)
3.只能在jdk1.8

订单模块添加Seata AT事务

1.父项目添加Seata依赖

  <dependency>
          <groupId>com.alibaba.cloud</groupId>
          <artifactId>spring-cloud-alibaba-seata</artifactId>
          <version>${spring-cloud-alibaba-seata.version}</version>
          <exclusions>
            <exclusion>
              <artifactId>seata-all</artifactId>
              <groupId>io.seata</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        **<dependency>
          <groupId>io.seata</groupId>
          <artifactId>seata-all</artifactId>
          <version>${seata.version}</version>
        </dependency>
        <dependency>**
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

2.在order中配置3个配置文件

  • application.yml,–事务组组名
spring:
 cloud:
    alibaba:
      seata:
        tx-service-group: order_tx_group
  • registry.conf–注册中心的地址
registry {
   
   
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "eureka"

  nacos {
   
   
    serverAddr = "localhost"
    namespace = ""
    cluster = "default"
  }
  eureka {
   
   
  #连接eureka,要从注册表发现seata-server
    serviceUrl = "http://localhost:8761/eureka"
    # application = "default"
    # weight = "1"
  }
  redis {
   
   
    serverAddr = "localhost:6379"
    db = "0"
    password = ""
    cluster = "default"
    timeout = "0"
  }
  zk {
   
   
    cluster = "default"
    serverAddr = "127.0.0.1:2181"
    session.timeout = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值