• 阿里分布式事务seata


    (一) seata 介绍

    • Seata 是一款阿里开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案
    • 这里演示学习使用SpringCloud/SpringBoot集成配置了Seata,并使用AT模式实现分布式事务回滚
    • Seata GitHub
    • Seata 官方文档
    • Seata Demo GitHub

    (二) Seata server 安装配置

    环境准备

    • Mac OS
    • Mysql8
    • Eureka注册中心

    GitHub 下载v1.1.0 Seata v1.1.0

    • unzip seata-server-1.1.0.zip
    • cd /seata/conf
    • 由于seatev1.1.0默认驱动是mysql5,在seata/lib目录下,将mysql-connector-java-8.0.19.jar版本的jar包替换原来的mysq5;修改file.conf中的driverClassName = “com.mysql.cj.jdbc.Driver”
    • 修改file.conf如下;修改为db模式,并且配置自己的mysql数据库链接;注意service配置中的vgroupMapping.licaibo_tx_group,其中licaibo_tx_group为自己定义,到时SpringBoot集成seata的时候需要保持一致
    ## transaction log store, only used in seata-server
    store {
      ## store mode: file、db
      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 {
        ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
        datasource = "dbcp"
        ## mysql/oracle/h2/oceanbase etc.
        dbType = "mysql"
        driverClassName = "com.mysql.cj.jdbc.Driver"
        url = "jdbc:mysql://localhost:3306/seat-server"
        user = "root"
        password = "root"
        minConn = 1
        maxConn = 10
        globalTable = "global_table"
        branchTable = "branch_table"
        lockTable = "lock_table"
        queryLimit = 100
      }
    
    
    service {
      #transaction service group mapping
      vgroupMapping.licaibo_tx_group = "default"
      #only support when registry.type=file, please don't set multiple addresses
      default.grouplist = "127.0.0.1:8091"
      #degrade, current not support
      enableDegrade = false
      #disable seata
      disableGlobalTransaction = false
    }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52

    在自己的seat-server数据库需要创建三张表,具体脚本在 Seata-mysql-script

    -- -------------------------------- The script used when storeMode is 'db' --------------------------------
    -- the table to store GlobalSession data
    CREATE TABLE IF NOT EXISTS `global_table`
    (
        `xid`                       VARCHAR(128) NOT NULL,
        `transaction_id`            BIGINT,
        `status`                    TINYINT      NOT NULL,
        `application_id`            VARCHAR(32),
        `transaction_service_group` VARCHAR(32),
        `transaction_name`          VARCHAR(128),
        `timeout`                   INT,
        `begin_time`                BIGINT,
        `application_data`          VARCHAR(2000),
        `gmt_create`                DATETIME,
        `gmt_modified`              DATETIME,
        PRIMARY KEY (`xid`),
        KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
        KEY `idx_transaction_id` (`transaction_id
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
  • 相关阅读:
    LeetCode每日一题:1822. 数组元素积的符号 (简单) 位运算
    六、python的csv模块
    python实现Flask GET Demo
    计算机导论实验——Linux基础入门
    Node编写更新用户头像接口
    吲哚菁绿ICG标记Polyacetal聚缩醛/HA透明质酸纳米载体|ICG-Polyacetal|ICG-SS-PEG-HA
    C_练习题 10
    HTML&CSS&HTTP
    Jenkins CICD过程常见异常
    C函数
  • 原文地址:https://blog.csdn.net/u014042146/article/details/128155438