• Seata入门开发


    连接:https://pan.baidu.com/s/14Wg4r6v7m9OAfRxtCBs9Ow?pwd=3phv

    1.  Seata配置文件application.yml
      1. server:
      2. port: 7091
      3. spring:
      4. application:
      5. name: seata-server
      6. logging:
      7. config: classpath:logback-spring.xml
      8. file:
      9. path: ${user.home}/logs/seata
      10. # extend:
      11. # logstash-appender:
      12. # destination: 127.0.0.1:4560
      13. # kafka-appender:
      14. # bootstrap-servers: 127.0.0.1:9092
      15. # topic: logback_to_logstash
      16. console:
      17. user:
      18. username: seata
      19. password: seata
      20. seata:
      21. config:
      22. # support: nacos, consul, apollo, zk, etcd3
      23. type: nacos
      24. nacos:
      25. server-addr: 127.0.0.1:8848
      26. namespace:
      27. group: SEATA_GROUP
      28. username:
      29. password:
      30. ##if use MSE Nacos with auth, mutex with username/password attribute
      31. #access-key: ""
      32. #secret-key: ""
      33. data-id: seataServer.properties
      34. registry:
      35. # support: nacos, eureka, redis, zk, consul, etcd3, sofa
      36. type: nacos
      37. nacos:
      38. application: seata-server
      39. server-addr: 127.0.0.1:8848
      40. group: SEATA_GROUP
      41. namespace:
      42. cluster: default
      43. username:
      44. password:
      45. ##if use MSE Nacos with auth, mutex with username/password attribute
      46. #access-key: ""
      47. #secret-key: ""
      48. store:
      49. # support: file 、 db 、 redis
      50. mode: db
      51. db:
      52. datasource: druid
      53. db-type: mysql
      54. driver-class-name: com.mysql.cj.jdbc.Driver
      55. url: jdbc:mysql://127.0.0.1:3306/seata?serverTimezone=Asia/Shanghai
      56. user: root
      57. password: 123456
      58. min-conn: 5
      59. max-conn: 100
      60. global-table: global_table
      61. branch-table: branch_table
      62. lock-table: lock_table
      63. distributed-lock-table: distributed_lock
      64. query-limit: 100
      65. max-wait: 5000
      66. server:
      67. service-port: 8091 #If not configured, the default is '${server.port} + 1000'
      68. max-commit-retry-timeout: -1
      69. max-rollback-retry-timeout: -1
      70. rollback-retry-timeout-unlock-enable: false
      71. enable-check-auth: true
      72. enable-parallel-request-handle: true
      73. retry-dead-threshold: 130000
      74. xaer-nota-retry-timeout: 60000
      75. recovery:
      76. handle-all-session-period: 1000
      77. undo:
      78. log-save-days: 7
      79. log-delete-period: 86400000
      80. session:
      81. branch-async-queue-size: 5000 #branch async remove queue size
      82. enable-branch-async-remove: false #enable to asynchronous remove branchSession
      83. security:
      84. secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
      85. tokenValidityInMilliseconds: 1800000
      86. ignore:
      87. urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
    2.  Nacos添加seataServer.properties
      1. transport.type=TCP
      2. transport.server=NIO
      3. transport.heartbeat=true
      4. transport.enableTmClientBatchSendRequest=false
      5. transport.enableRmClientBatchSendRequest=true
      6. transport.enableTcServerBatchSendResponse=false
      7. transport.rpcRmRequestTimeout=30000
      8. transport.rpcTmRequestTimeout=30000
      9. transport.rpcTcRequestTimeout=30000
      10. transport.threadFactory.bossThreadPrefix=NettyBoss
      11. transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
      12. transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
      13. transport.threadFactory.shareBossWorker=false
      14. transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
      15. transport.threadFactory.clientSelectorThreadSize=1
      16. transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
      17. transport.threadFactory.bossThreadSize=1
      18. transport.threadFactory.workerThreadSize=default
      19. transport.shutdown.wait=3
      20. transport.serialization=seata
      21. transport.compressor=none
      22. service.vgroupMapping.my_test_tx_group=default
      23. service.default.grouplist=127.0.0.1:8091
      24. service.enableDegrade=false
      25. service.disableGlobalTransaction=false
      26. client.rm.asyncCommitBufferLimit=10000
      27. client.rm.lock.retryInterval=10
      28. client.rm.lock.retryTimes=30
      29. client.rm.lock.retryPolicyBranchRollbackOnConflict=true
      30. client.rm.reportRetryCount=5
      31. client.rm.tableMetaCheckEnable=true
      32. client.rm.tableMetaCheckerInterval=60000
      33. client.rm.sqlParserType=druid
      34. client.rm.reportSuccessEnable=false
      35. client.rm.sagaBranchRegisterEnable=false
      36. client.rm.sagaJsonParser=fastjson
      37. client.rm.tccActionInterceptorOrder=-2147482648
      38. client.tm.commitRetryCount=5
      39. client.tm.rollbackRetryCount=5
      40. client.tm.defaultGlobalTransactionTimeout=60000
      41. client.tm.degradeCheck=false
      42. client.tm.degradeCheckAllowTimes=10
      43. client.tm.degradeCheckPeriod=2000
      44. client.tm.interceptorOrder=-2147482648
      45. client.undo.dataValidation=true
      46. client.undo.logSerialization=jackson
      47. client.undo.onlyCareUpdateColumns=true
      48. server.undo.logSaveDays=7
      49. server.undo.logDeletePeriod=86400000
      50. client.undo.logTable=undo_log
      51. client.undo.compress.enable=true
      52. client.undo.compress.type=zip
      53. client.undo.compress.threshold=64k
      54. tcc.fence.logTableName=tcc_fence_log
      55. tcc.fence.cleanPeriod=1h
      56. log.exceptionRate=100
      57. store.mode=db
      58. store.lock.mode=file
      59. store.session.mode=file
      60. store.file.dir=file_store/data
      61. store.file.maxBranchSessionSize=16384
      62. store.file.maxGlobalSessionSize=512
      63. store.file.fileWriteBufferCacheSize=16384
      64. store.file.flushDiskMode=async
      65. store.file.sessionReloadReadSize=100
      66. store.db.datasource=druid
      67. store.db.dbType=mysql
      68. store.db.driverClassName=com.mysql.cj.jdbc.Driver
      69. store.db.url=jdbc:mysql://127.0.0.1:3306/seata?serverTimezone=Asia/Shanghai
      70. store.db.user=root
      71. store.db.password=123456
      72. store.db.minConn=5
      73. store.db.maxConn=30
      74. store.db.globalTable=global_table
      75. store.db.branchTable=branch_table
      76. store.db.distributedLockTable=distributed_lock
      77. store.db.queryLimit=100
      78. store.db.lockTable=lock_table
      79. store.db.maxWait=5000
      80. store.redis.mode=single
      81. store.redis.single.host=127.0.0.1
      82. store.redis.single.port=6379
      83. store.redis.maxConn=10
      84. store.redis.minConn=1
      85. store.redis.maxTotal=100
      86. store.redis.database=0
      87. store.redis.queryLimit=100
      88. server.recovery.committingRetryPeriod=1000
      89. server.recovery.asynCommittingRetryPeriod=1000
      90. server.recovery.rollbackingRetryPeriod=1000
      91. server.recovery.timeoutRetryPeriod=1000
      92. server.maxCommitRetryTimeout=-1
      93. server.maxRollbackRetryTimeout=-1
      94. server.rollbackRetryTimeoutUnlockEnable=false
      95. server.distributedLockExpireTime=10000
      96. server.xaerNotaRetryTimeout=60000
      97. server.session.branchAsyncQueueSize=5000
      98. server.session.enableBranchAsyncRemove=false
      99. server.enableParallelRequestHandle=false
      100. metrics.enabled=false
      101. metrics.registryType=compact
      102. metrics.exporterList=prometheus
      103. metrics.exporterPrometheusPort=9898

    3.  Seata数据库建表sql
      1. /*
      2. Navicat MySQL Data Transfer
      3. Source Server : mysql
      4. Source Server Version : 80020
      5. Source Host : localhost:3306
      6. Source Database : seata
      7. Target Server Type : MYSQL
      8. Target Server Version : 80020
      9. File Encoding : 65001
      10. Date: 2022-07-27 18:35:46
      11. */
      12. SET FOREIGN_KEY_CHECKS=0;
      13. -- ----------------------------
      14. -- Table structure for `branch_table`
      15. -- ----------------------------
      16. DROP TABLE IF EXISTS `branch_table`;
      17. CREATE TABLE `branch_table` (
      18. `branch_id` bigint NOT NULL,
      19. `xid` varchar(128) NOT NULL,
      20. `transaction_id` bigint DEFAULT NULL,
      21. `resource_group_id` varchar(32) DEFAULT NULL,
      22. `resource_id` varchar(256) DEFAULT NULL,
      23. `branch_type` varchar(8) DEFAULT NULL,
      24. `status` tinyint DEFAULT NULL,
      25. `client_id` varchar(64) DEFAULT NULL,
      26. `application_data` varchar(2000) DEFAULT NULL,
      27. `gmt_create` datetime(6) DEFAULT NULL,
      28. `gmt_modified` datetime(6) DEFAULT NULL,
      29. PRIMARY KEY (`branch_id`),
      30. KEY `idx_xid` (`xid`)
      31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      32. -- ----------------------------
      33. -- Records of branch_table
      34. -- ----------------------------
      35. -- ----------------------------
      36. -- Table structure for `global_table`
      37. -- ----------------------------
      38. DROP TABLE IF EXISTS `global_table`;
      39. CREATE TABLE `global_table` (
      40. `xid` varchar(128) NOT NULL,
      41. `transaction_id` bigint DEFAULT NULL,
      42. `status` tinyint NOT NULL,
      43. `application_id` varchar(32) DEFAULT NULL,
      44. `transaction_service_group` varchar(32) DEFAULT NULL,
      45. `transaction_name` varchar(128) DEFAULT NULL,
      46. `timeout` int DEFAULT NULL,
      47. `begin_time` bigint DEFAULT NULL,
      48. `application_data` varchar(2000) DEFAULT NULL,
      49. `gmt_create` datetime DEFAULT NULL,
      50. `gmt_modified` datetime DEFAULT NULL,
      51. PRIMARY KEY (`xid`),
      52. KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
      53. KEY `idx_transaction_id` (`transaction_id`)
      54. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      55. -- ----------------------------
      56. -- Records of global_table
      57. -- ----------------------------
      58. -- ----------------------------
      59. -- Table structure for `lock_table`
      60. -- ----------------------------
      61. DROP TABLE IF EXISTS `lock_table`;
      62. CREATE TABLE `lock_table` (
      63. `row_key` varchar(128) NOT NULL,
      64. `xid` varchar(96) DEFAULT NULL,
      65. `transaction_id` bigint DEFAULT NULL,
      66. `branch_id` bigint NOT NULL,
      67. `resource_id` varchar(256) DEFAULT NULL,
      68. `table_name` varchar(32) DEFAULT NULL,
      69. `pk` varchar(36) DEFAULT NULL,
      70. `gmt_create` datetime DEFAULT NULL,
      71. `gmt_modified` datetime DEFAULT NULL,
      72. PRIMARY KEY (`row_key`),
      73. KEY `idx_branch_id` (`branch_id`)
      74. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      75. -- ----------------------------
      76. -- Records of lock_table
      77. -- ----------------------------
    4.  Seata控制台启动、访问
      启动Nacos并添加seataServer.properties配置,Mysql创建seata数据库并执行建表语句,双击seata-server.bat启动Seata服务,Seata服务启动后Nacos服务列表可以看到该服务, Seata控制台访问: http://localhost:7091,用户名和密码均为seata

    5.  Seata分布式事务测试
      1. "1.0" encoding="UTF-8"?>
      2. "http://maven.apache.org/POM/4.0.0"
      3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5. 4.0.0
      6. com.seata
      7. seatatest
      8. pom
      9. 1.0-SNAPSHOT
      10. <module>seata-commonmodule>
      11. <module>seata-ordermodule>
      12. <module>seata-accountmodule>
      13. <module>seata-webmodule>
      14. UTF-8
      15. 1.8
      16. 1.8
      17. 1.1.10
      18. Hoxton.SR8
      19. 2.3.2.RELEASE
      20. 2.2.4.RELEASE
      21. 1.2.35
      22. 3.6
      23. 1.0-SNAPSHOT
      24. 2.1.0
      25. org.springframework.cloud
      26. spring-cloud-dependencies
      27. ${spring-cloud.version}
      28. pom
      29. import
      30. org.springframework.boot
      31. spring-boot-dependencies
      32. ${springboot.version}
      33. pom
      34. import
      35. com.alibaba.cloud
      36. spring-cloud-alibaba-dependencies
      37. ${springcloudalibaba.version}
      38. pom
      39. import
      40. com.alibaba
      41. druid
      42. ${druid.version}
      43. com.alibaba
      44. fastjson
      45. ${fastjson.version}
      46. org.apache.commons
      47. commons-lang3
      48. ${commons-lang3.version}
      49. com.seata
      50. seata-common
      51. ${seata-common.version}
      52. org.mybatis.spring.boot
      53. mybatis-spring-boot-starter
      54. ${mybatis.version}
      55. org.springframework.boot
      56. spring-boot-maven-plugin
      1. "1.0" encoding="UTF-8"?>
      2. "http://maven.apache.org/POM/4.0.0"
      3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5. seatatest
      6. com.seata
      7. 1.0-SNAPSHOT
      8. 4.0.0
      9. seata-common
      10. com.alibaba.cloud
      11. spring-cloud-starter-alibaba-seata
      12. com.alibaba.nacos
      13. nacos-client
      14. 1.4.0
      15. org.springframework.boot
      16. spring-boot-starter-web
      17. org.springframework.boot
      18. spring-boot-starter-test
      19. test
      20. com.alibaba.cloud
      21. spring-cloud-starter-alibaba-nacos-discovery
      22. com.alibaba.cloud
      23. spring-cloud-starter-alibaba-nacos-config
      24. org.springframework.boot
      25. spring-boot-devtools
      26. runtime
      27. true
      28. mysql
      29. mysql-connector-java
      30. runtime
      31. org.projectlombok
      32. lombok
      33. org.springframework.boot
      34. spring-boot-starter-test
      35. test
      36. org.mybatis.spring.boot
      37. mybatis-spring-boot-starter
      38. com.alibaba
      39. druid
      40. org.springframework.boot
      41. spring-boot-starter-data-redis
      42. org.apache.commons
      43. commons-pool2
      44. com.alibaba
      45. fastjson
      46. commons-codec
      47. commons-codec
      48. org.apache.commons
      49. commons-lang3
      1. "1.0" encoding="UTF-8"?>
      2. "http://maven.apache.org/POM/4.0.0"
      3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5. seatatest
      6. com.seata
      7. 1.0-SNAPSHOT
      8. 4.0.0
      9. seata-web
      10. com.seata
      11. seata-common
      12. org.springframework.cloud
      13. spring-cloud-starter-openfeign
      1. "1.0" encoding="UTF-8"?>
      2. "http://maven.apache.org/POM/4.0.0"
      3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5. seatatest
      6. com.seata
      7. 1.0-SNAPSHOT
      8. 4.0.0
      9. seata-order
      10. com.seata
      11. seata-common
      1. "1.0" encoding="UTF-8"?>
      2. "http://maven.apache.org/POM/4.0.0"
      3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5. seatatest
      6. com.seata
      7. 1.0-SNAPSHOT
      8. 4.0.0
      9. seata-account
      10. com.seata
      11. seata-common

      1. server:
      2. port: 8088
      3. servlet:
      4. context-path: /
      5. spring:
      6. cloud:
      7. nacos:
      8. discovery:
      9. server-addr: 127.0.0.1:8848
      10. alibaba:
      11. seata:
      12. tx-service-group: my_test_tx_group
      13. application:
      14. name: seata-web
      15. seata:
      16. service:
      17. vgroup-mapping:
      18. my_test_tx_group: default
      19. grouplist:
      20. default: 127.0.0.1:8091
      21. enable-degrade: false
      22. disable-global-transaction: false
      1. server:
      2. port: 8070
      3. servlet:
      4. context-path: /
      5. spring:
      6. datasource:
      7. type: com.alibaba.druid.pool.DruidDataSource
      8. driver-class-name: com.mysql.cj.jdbc.Driver
      9. url: jdbc:mysql://localhost:3306/db_account?serverTimezone=Asia/Shanghai
      10. username: root
      11. password: 123456
      12. cloud:
      13. nacos:
      14. discovery:
      15. server-addr: 127.0.0.1:8848
      16. alibaba:
      17. seata:
      18. tx-service-group: my_test_tx_group
      19. application:
      20. name: seata-account
      21. mybatis:
      22. mapper-locations: classpath:mybatis/mapper/*.xml
      23. #seata:
      24. # config:
      25. # type: nacos
      26. # nacos:
      27. # server-addr: 127.0.0.1:8848
      28. # group: SEATA_GROUP
      29. # namespace: ""
      30. # registry:
      31. # type: nacos
      32. # nacos:
      33. # application: seata-server
      34. # server-addr: 127.0.0.1:8848
      35. # group: SEATA_GROUP
      36. # namespace: ""
      37. seata:
      38. service:
      39. vgroup-mapping:
      40. my_test_tx_group: default
      41. grouplist:
      42. default: 127.0.0.1:8091
      43. enable-degrade: false
      44. disable-global-transaction: false
      1. server:
      2. port: 8090
      3. servlet:
      4. context-path: /
      5. spring:
      6. datasource:
      7. type: com.alibaba.druid.pool.DruidDataSource
      8. driver-class-name: com.mysql.cj.jdbc.Driver
      9. url: jdbc:mysql://localhost:3306/db_order?serverTimezone=Asia/Shanghai
      10. username: root
      11. password: 123456
      12. cloud:
      13. nacos:
      14. discovery:
      15. server-addr: 127.0.0.1:8848
      16. alibaba:
      17. seata:
      18. tx-service-group: my_test_tx_group
      19. application:
      20. name: seata-order
      21. mybatis:
      22. mapper-locations: classpath:mybatis/mapper/*.xml
      23. seata:
      24. service:
      25. vgroup-mapping:
      26. my_test_tx_group: default
      27. grouplist:
      28. default: 127.0.0.1:8091
      29. enable-degrade: false
      30. disable-global-transaction: false


    6.  Seata分布式事务回滚



    https://blog.csdn.net/caoli201314?type=blog

  • 相关阅读:
    字符流Reader和Writer
    人工智能与电力:自动化、集中化和规模化的伦理挑战
    【UI】element-ui的el-dialog的遮罩层在模态框的前面bug
    基于Java+SpringBoot+Vue前后端分离农产品直卖平台设计和实现
    华为ensp搭建VRRP主备份配置
    Junit4 一直处于运行中的排查过程
    企业架构LNMP学习笔记23
    解析富有童趣的人工智能早教机器人
    在Linux系统中搜索当前路径及其子目录下所有PDF文件中是否包含特定字符串
    nvm的安装和使用
  • 原文地址:https://blog.csdn.net/tongxin_tongmeng/article/details/126038705