springcloud alibaba 整合 seata 完整 安装和配置

1.下载seata

  1. 下载地址 :https://github.com/seata/seata/releases 我使用的版本是1.4.1

springcloud alibaba 整合 seata 完整 安装和配置_第1张图片

2.配置服务端

  1. 启动nacos 创建seata namespace 
  2.  修改registry.conf
    registry {
      # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
      type = "nacos"
      loadBalance = "RandomLoadBalance"
      loadBalanceVirtualNodes = 10
    
      nacos {
        application = "seata-server"
        serverAddr = "127.0.0.1:8849"
        group = "seata_group"
        namespace = "d3cca02c-6317-474d-bced-6715cf3fa658"
        cluster = "default"
      }
    
    }
    
    config {
    
      type = "file"
      file {
        name = "file.conf"
      }
    }
    

    namesapce 为第一步当中创建的命名空间ID group 为自己第一步创建的group 我这面用的是小写 跟源码发现seata 自动转换大小写 (不知道是不是会影响,后续没去验证建议小写) 配置用的是file 类型

  3. 修改file.conf 无用配置都给去掉了

    ## transaction log store, only used in seata-server
    store {
      ## store mode: file、db、redis
      mode = "db"
    
      ## file store property
      file {
        ## store location dir
        dir = "sessionStore"
        # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
        maxBranchSessionSize = 16384
        # globe session size , if exceeded throws exceptions
        maxGlobalSessionSize = 512
        # file buffer size , if exceeded allocate new buffer
        fileWriteBufferCacheSize = 16384
        # when recover batch read size
        sessionReloadReadSize = 100
        # async, sync
        flushDiskMode = async
      }
    
      ## database store property
      db {
        datasource = "druid"
        dbType = "mysql"
        driverClassName = "com.mysql.jdbc.Driver"
        url = "jdbc:mysql://127.0.0.1:3306/seata"
        user = "root"
        password = "123456"
        minConn = 5
        maxConn = 100
        globalTable = "global_table"
        branchTable = "branch_table"
        lockTable = "lock_table"
        queryLimit = 100
        maxWait = 5000
      }
    
      
    
    }
    

     5,创建数据库 https://github.com/seata/seata/tree/develop/script/server 这是readme当中 给的官方sql 脚本自己去下载 创建数据库

    6.启动  bin/seata-server.bat 或者 seata-server.sh 启动成功端口默认8091

3.配置seata客户端

  1. 引入依赖
  2.         
                com.alibaba.cloud
                spring-cloud-starter-alibaba-seata
                2021.1
            
            
                io.seata
                seata-spring-boot-starter
                1.3.0
            

  3.  服务端处理bootstrap.yml 文件外新增 application.yml 内容如下
    seata:
      enabled: true
      application-id: #自己服务ID
      tx-service-group: test_tx_group
      enable-auto-data-source-proxy: true
      use-jdk-proxy: false
      excludes-for-auto-proxying: firstClassNameForExclude,secondClassNameForExclude
      client:
        rm:
          async-commit-buffer-limit: 1000
          report-retry-count: 5
          table-meta-check-enable: false
          report-success-enable: false
          saga-branch-register-enable: false
          lock:
            retry-interval: 10
            retry-times: 30
            retry-policy-branch-rollback-on-conflict: true
        tm:
          commit-retry-count: 5
          rollback-retry-count: 5
        undo:
          data-validation: true
          log-serialization: jackson
          log-table: undo_log
        log:
          exceptionRate: 100
      service:
        vgroup-mapping:
          renren_tx_group: default
        enable-degrade: false
        disable-global-transaction: false
      transport:
        shutdown:
          wait: 3
        thread-factory:
          boss-thread-prefix: NettyBoss
          worker-thread-prefix: NettyServerNIOWorker
          server-executor-thread-prefix: NettyServerBizHandler
          share-boss-worker: false
          client-selector-thread-prefix: NettyClientSelector
          client-selector-thread-size: 1
          client-worker-thread-prefix: NettyClientWorkerThread
          worker-thread-size: default
          boss-thread-size: 1
        type: TCP
        server: NIO
        heartbeat: true
        serialization: seata
        compressor: none
        enable-client-batch-send-request: true
      config:
        type: file
      registry:
        type: nacos
        nacos:
          application: seata-server
          #修改对应端口
          server-addr: localhost:8849
          #修改对应namespace
          namespace: d3cca02c-6317-474d-bced-6715cf3fa658
          userName: ""
          password: ""
          #和服务端保持一致
          group: seata_group

    3.关注下上述文件备注

  4. bootstrap.yml 新增配置

  5. spring:
      cloud:
        alibaba:
          seata:
            #和上述yml 配置要求一致
            tx-service-group: test_tx_group

4 .使用 方法前添加注解 

@GlobalTransactional
@Transactional(rollbackFor = Exception.class)

5.项目运行 情况

1.注意项:1.要不要README 中的 config.txt 去加载到nacos 我这面使用的是file 配置不需要

 

                  2.项目启动后 no service avaliable  seata 的nacos 配置有问题关注上述配置文件的注释

6.其他官方文档 参阅 Seata 官方原理看官方  

你可能感兴趣的:(spring,boot,配置,java,springcloud)