好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

seata springcloud整合教程与遇到的坑

SEATA概要

seata 是alibaba 出的一款分布式事务管理器,他有侵入性小,实现简单等特点。我们能够使用seata 实现分布式事务管理,

是微服务必备的组件。他可以实现在微服务之间的事务管理,也可以实现多个数据源的事务管理。

seata 在阿里内部,和众多的公司都有应用,因此我们可以放心的使用它。

依赖

?

1

2

3

4

<dependency>

     <groupId>com.alibaba.cloud</groupId>

     <artifactId>spring-cloud-starter-alibaba-seata</artifactId>

</dependency>

建表

AT模式客户端服务的数据库都需要建表undo_log
否则报错

java.sql.SQLSyntaxErrorException: Table ‘psr_enterprise_control_test.undo_log' doesn't exist

官方GIT脚本文件

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

-- for AT mode you must to init this sql for you business database. the seata server not need it.

CREATE TABLE IF NOT EXISTS `undo_log`

(

     `branch_id`     BIGINT       NOT NULL COMMENT 'branch transaction id' ,

     `xid`           VARCHAR( 128 ) NOT NULL COMMENT 'global transaction id' ,

     `context`       VARCHAR( 128 ) NOT NULL COMMENT 'undo_log context,such as serialization' ,

     `rollback_info` LONGBLOB     NOT NULL COMMENT 'rollback info' ,

     `log_status`    INT( 11 )      NOT NULL COMMENT '0:normal status,1:defense status' ,

     `log_created`   DATETIME( 6 )  NOT NULL COMMENT 'create datetime' ,

     `log_modified`  DATETIME( 6 )  NOT NULL COMMENT 'modify datetime' ,

     UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)

) ENGINE = InnoDB

   AUTO_INCREMENT = 1

   DEFAULT CHARSET = utf8 COMMENT = 'AT transaction mode undo table' ;

配置

application.yml

?

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

seata:

   enabled: true

   enable-auto-data-source-proxy: true

   tx-service-group: my_test_tx_group # 与seata.service.vgroup-mapping一致

   registry:

     type: nacos # 与seata注册中心相同

     nacos:

       application: seata-server

       server-addr: ${PSR_NACOS:localhost: 8848 }

       namespace: test

       group: application

       cluster: default

   config:

     type: nacos # 与seata配置中心相同

     nacos:

       server-addr: ${PSR_NACOS:localhost: 8848 }

       group: seata

       namespace: test

   service:

     vgroup-mapping:

       my_test_tx_group: default # 事务分组名

     disable-global-transaction: false

   client:

     rm:

       report-success-enable: false

启用全局事务

@GlobalTransactional

到此这篇关于seata springcloud 整合教程与遇到的坑的文章就介绍到这了,更多相关seata springcloud整合内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

原文链接:https://blog.csdn.net/zhoudingding/article/details/118518708

查看更多关于seata springcloud整合教程与遇到的坑的详细内容...

  阅读:21次