1.Seata-Server的配置

本文章是在AT模式-File做注册配置中心的基础上进行。

1.1Nacos配置信息配置

  1. 启动nacos
  2. 准备config.txt,内容如下:
    1. service.vgroupMapping.my_test_tx_group=default
    2. store.mode=db
    3. store.db.datasource=druid
    4. store.db.dbType=mysql
    5. store.db.driverClassName=com.mysql.jdbc.Driver
    6. store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
    7. store.db.user=root #改成自己的
    8. store.db.password=888888 #改成自己的
    9. store.db.minConn=5
    10. store.db.maxConn=30
    11. store.db.globalTable=global_table
    12. store.db.branchTable=branch_table
    13. store.db.queryLimit=100
    14. store.db.lockTable=lock_table
    15. store.db.maxWait=5000
    注:config.txt位置放在seata的Home目录下。
    3.将config.txt中的配置配置到nacos上(通过脚本)
    https://github.com/seata/seata/blob/develop/script/config-center/nacos/nacos-config.sh 将此脚本放在seata的conf目录下后,执行以下命令:
    1. sh nacos-config.sh -h nacosip -p nacos端口 -g nacos配置文件的组 -t 你的namespace号(若是public可省略此选项) -u nacos用户名 -w nacos密码
    注:windows用户可以用git bash来执行哦!!
    4.观察结果
    image.png

1.2数据库的变化

1.新建seata数据库
2.在库中新建3张数据表

  1. -- -------------------------------- The script used when storeMode is 'db' --------------------------------
  2. -- the table to store GlobalSession data
  3. CREATE TABLE IF NOT EXISTS `global_table`
  4. (
  5. `xid` VARCHAR(128) NOT NULL,
  6. `transaction_id` BIGINT,
  7. `status` TINYINT NOT NULL,
  8. `application_id` VARCHAR(32),
  9. `transaction_service_group` VARCHAR(32),
  10. `transaction_name` VARCHAR(128),
  11. `timeout` INT,
  12. `begin_time` BIGINT,
  13. `application_data` VARCHAR(2000),
  14. `gmt_create` DATETIME,
  15. `gmt_modified` DATETIME,
  16. PRIMARY KEY (`xid`),
  17. KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
  18. KEY `idx_transaction_id` (`transaction_id`)
  19. ) ENGINE = InnoDB
  20. DEFAULT CHARSET = utf8;
  21. -- the table to store BranchSession data
  22. CREATE TABLE IF NOT EXISTS `branch_table`
  23. (
  24. `branch_id` BIGINT NOT NULL,
  25. `xid` VARCHAR(128) NOT NULL,
  26. `transaction_id` BIGINT,
  27. `resource_group_id` VARCHAR(32),
  28. `resource_id` VARCHAR(256),
  29. `branch_type` VARCHAR(8),
  30. `status` TINYINT,
  31. `client_id` VARCHAR(64),
  32. `application_data` VARCHAR(2000),
  33. `gmt_create` DATETIME(6),
  34. `gmt_modified` DATETIME(6),
  35. PRIMARY KEY (`branch_id`),
  36. KEY `idx_xid` (`xid`)
  37. ) ENGINE = InnoDB
  38. DEFAULT CHARSET = utf8;
  39. -- the table to store lock data
  40. CREATE TABLE IF NOT EXISTS `lock_table`
  41. (
  42. `row_key` VARCHAR(128) NOT NULL,
  43. `xid` VARCHAR(96),
  44. `transaction_id` BIGINT,
  45. `branch_id` BIGINT NOT NULL,
  46. `resource_id` VARCHAR(256),
  47. `table_name` VARCHAR(32),
  48. `pk` VARCHAR(36),
  49. `gmt_create` DATETIME,
  50. `gmt_modified` DATETIME,
  51. PRIMARY KEY (`row_key`),
  52. KEY `idx_branch_id` (`branch_id`)
  53. ) ENGINE = InnoDB
  54. DEFAULT CHARSET = utf8;

1.3Seata-Server配置和启动

1.修改seata的conf目录下的registry.conf文件

  1. registry {
  2. # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  3. type = "nacos"
  4. nacos {
  5. application = "seata-server"
  6. serverAddr = "127.0.0.1:8848"
  7. group = "SEATA_GROUP"
  8. namespace = ""
  9. cluster = "default"
  10. username = "nacos"
  11. password = "nacos"
  12. }
  13. }
  14. config {
  15. # file、nacos 、apollo、zk、consul、etcd3
  16. type = "nacos"
  17. nacos {
  18. serverAddr = "127.0.0.1:8848"
  19. namespace = ""
  20. group = "SEATA_GROUP"
  21. username = "nacos"
  22. password = "nacos"
  23. }
  24. }

2.启动seata-server
①linus/mac

  1. sh seata-server.sh

②windows

  1. .\seata-server.bat

2.各个微服务的配置

  1. seata:
  2. tx-service-group: my_test_tx_group
  3. registry:
  4. type: nacos
  5. nacos:
  6. server-addr: localhost:8848
  7. username: nacos
  8. password: nacos
  9. config:
  10. type: nacos
  11. nacos:
  12. server-addr: localhost:8848
  13. username: nacos
  14. password: nacos

码云:https://gitee.com/gao_xi/seata-demo.git