seata最新版本微服务事务搭建

环境搭建seata1.5.2版本

说明,高版本的seata必须要用高版本的springboot、springcloud、springcloudAlibaba,否则会报很多无法解决的错误可以参考版本说明

seata依赖

		<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.seata</groupId>
                    <artifactId>seata-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter -->
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>
            <version>1.5.2</version>
        </dependency>

服务端yml配置文件(高版本中将file.conf等文件都集成到了yml中)

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  service:
    vgroup-mapping:
      default-tx-group: default
      # grouplist:
      # default: 127.0.0.1:8091
    enable-degrade: false
    disable-global-transaction: false
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      #namespace: 4a5bdb96-a1a7-4a29-b0e0-ea14a0ffa083
      group: SEATA_GROUP
      username: nacos
      password: nacos
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key: ""
      #secret-key: ""
      #data-id: seataServer.properties
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    preferred-networks: 30.240.*
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      #namespace: 4a5bdb96-a1a7-4a29-b0e0-ea14a0ffa083
      cluster: default
      username: nacos
      password: nacos
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key: ""
      #secret-key: ""
  store:
    # support: file 、 db 、 redis
    mode: db
    session:
      mode: db
    lock:
      mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.48.3:3306/cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
      user: root
      password: root
      min-conn: 5
      max-conn: 100
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 100
      max-wait: 5000
  #  server:
  #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

客户端yml配置文件(高版本中将file.conf等文件都集成到了yml中)

server:
  port: 2002

spring:
  application:
    name: seata-storage-service
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/seata_storage?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root
    password: root

feign:
  hystrix:
    enabled: false

logging:
  level:
    io:
      seata: info

mybatis:
  mapperLocations: classpath:mapper/*.xml
seata:
  application-id: ${spring.application.name}
  enabled: true
  tx-service-group: default-tx-group #事务组名称
  service:
    vgroup-mapping:
      default-tx-group: default
  config:
    type: nacos
    nacos:
      group: SEATA_GROUP
      server-addr: 127.0.0.1:8848
      username: nacos
      password: nacos

  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: localhost:8848
      username: nacos
      password: nacos
      cluster: default
      group: SEATA_GROUP
  enable-auto-data-source-proxy: false


其中特别要注意事务组名称tx-service-group: default-tx-group一定要和服务端的一致

seata:
  service:
    vgroup-mapping:
      default-tx-group: default #事务组名称

如下
!](https://img-blog.csdnimg.cn/b4d0a6456f6f4e6fa06376e2e1e16ebd.png)

注意

  1. 当seata回滚失败的时候会将错误信息记录在\seata-server-1.5.2\seata\bin\file_store\data\root.data下,清除里边信息才不会报错
  2. nacos为内置derby数据库时,是不支持多用户访问,必须将其他服务停掉才能重启nacos
  3. 配置文件将mode改为db无效时,看\seata-server-1.5.2\seata\lib\jdbc下jar包和使用的版本是否正确,seata自己的jar包是5的版本,两个版本不能共存
  4. 如果配置了config到nacos,一定要注意将config.txt的值上传到nacos的配置文件的值是否相同(我就遇到明明yml中配置了db却无法写入db,走的还是默认的file)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值