seata分布式事务的搭建与使用


seata1.3.0 服务端的搭建

1.从官网下载seata-server-1.3.0

https://github.com/seata/seata/releases/tag/v1.3.0

也可以百度云下载seata-server-1.3.0

链接:https://pan.baidu.com/s/1Xmilth4Xs81CJqclmMKj7A
提取码:1ysf

2.下载以后conf目录有两个配置文件,一个是注册配置文件,另一个是file配置文件

注册配置文件用nacos的话,注意seata-server服务端与连接到该服务端的客户端是在一个group下面,否则客户端会报错无法从nacos注册服务器找到服务端。

 file里面可以配置数据库

## transaction log store, only used in server side
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)/HikariDataSource(hikari) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost:3306/seata"
    user = "root"
    password = "root"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
}
## server configuration, only used in server side
server {
  recovery {
    #schedule committing retry period in milliseconds
    committingRetryPeriod = 1000
    #schedule asyn committing retry period in milliseconds
    asynCommittingRetryPeriod = 1000
    #schedule rollbacking retry period in milliseconds
    rollbackingRetryPeriod = 1000
    #schedule timeout retry period in milliseconds
    timeoutRetryPeriod = 1000
  }
  undo {
    logSaveDays = 7
    #schedule delete expired undo_log in milliseconds
    logDeletePeriod = 86400000
  }
  #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
  maxCommitRetryTimeout = "-1"
  maxRollbackRetryTimeout = "-1"
  rollbackRetryTimeoutUnlockEnable = false
}

## metrics configuration, only used in server side
metrics {
  enabled = false
  registryType = "compact"
  # multi exporters use comma divided
  exporterList = "prometheus"
  exporterPrometheusPort = 9898
}

同时搭建seata-server服务所依赖的数据库,global_tablesql,branch_table,lock_table语句见https://gitee.com/xiaoyinjun/seata-demo/blob/master/sql/seata.sql

配置好文件之后,启动脚本nohup ./seata-server.sh -p 8091 -h  ******(绑定的ip地址)就可以执行了。

客户端代码示例见https://gitee.com/xiaoyinjun/seata-demo.git。如果按照以上搭建seata-server服务器,搭建客户端代码示例中所需要的数据库,建库语句在sql目录里面。就可以一键运行了。

客户端示例的file的配置文件有个事务组可以自定义

service {
  vgroupMapping.fsp_tx_group = "default" #修改自定义事务组名称
  default.grouplist = "127.0.0.1:8091"
  enableDegrade = false
  disable = false
  max.commit.retry.timeout = "-1"
  max.rollback.retry.timeout = "-1"
  disableGlobalTransaction = false
}

 但是接下来的springboot的配置文件也需要和他一致

spring:
  cloud:
    alibaba:
      seata:
        tx-service-group: fsp_tx_group

 同时客户端file里面的数据库配置,register.conf注册服务器配置同上面的seata-server配置一样。demo都已经是配置好了的。

seata官方文档见地址https://seata.io/zh-cn/docs/overview/what-is-seata.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM