The term to describe

Transaction Coordinator (TC) - The Transaction Coordinator maintains the status of global and branch transactions and drives global transactions to be committed or rolled back. TM (Transaction Manager) - The Transaction Manager defines the scope of a global Transaction: start, commit, or roll back the global Transaction. Resource Manager (RM) - The Resource Manager manages the resources for branch transaction processing, talks with TCS to register branch transactions and report the status of branch transactions, and drives branch transactions to commit or roll back.Copy the code

TC configuration for SEATA (Server for SEATA)

Configure a mapped volume on the Rancher

Registry {type = "nacos" loadBalance = "RandomLoadBalance" loadBalanceVirtualNodes = 10 nacos { application = "seata-server" serverAddr = "nacos" group="SEATA_GROUP" namespace = "seata_namespace_id" cluster = "default" username: "nacos" password: "nacos" } } config { type = "nacos" nacos { serverAddr = "nacos" namespace = "seata_namespace_id" group = "SEATA_GROUP" Username: "nacos" password: "nacos"}} ps:registry registration information config Configuration information, use nacos to register configurationCopy the code

Configuring the Mirror Service

The service must be in the same namespace as NACOS, otherwise it cannot register with NACOS

For port mapping, the default server uses 8091 image docker. IO/Seataio/setA-server :1.4.0

SEATA_CONFIG_NAME = file:/root/seata-config/registry

Configure a mapped volume. The volume name is the mapped volume configured in the first step

Start the service to view logs (configure nacOS before starting)

Configuration nacos

Create the SeATA namespace

The namespace ID must be the same as the namespace = "seatA_namespace_id" configuration file provided for seATA

View the configuration information after starting the Seata server

Nacos project starts configuration

Tx-service-group: ${spring.application.name} application-id: ${spring.application.name} application-id: ${spring.application.name} registry: type: nacos nacos: # "seata-server" serverAddr: ${spring.cloud.nacos.discovery.server-addr} group: "SEATA_GROUP" namespace: "seata_namespace_id" cluster: "default" username: "nacos" password: "nacos" config: type: nacos nacos: serverAddr: ${spring.cloud.nacos.discovery.server-addr} group: "SEATA_GROUP" namespace: "seata_namespace_id" username: "Nacos" password: "nacos" ps: ${spring. Cloud. Nacos. Discovery. Server - addr} is the registered address 127.0.0.1 nacos: 8848 tx - service - group: ${spring.application.name} project startup configuration file, need to configure related files in a separateCopy the code

Configuring the Database

CREATE TABLE IF NOT EXISTS `undo_log`
(
    `branch_id`     BIGINT(20)   NOT NULL COMMENT 'branch transaction id',
    `xid`           VARCHAR(100) 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';
Copy the code

Project configuration

Add project POM dependencies

 <dependencies>
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>
            <version>1.4.1</version>
        </dependency>
        <! Seata1.0.0 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.seata</groupId>
                    <artifactId>seata-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
Copy the code

Code transaction addition

Sample code for @globalTransactional (rollbackFor = exception.class) : @GlobalTransactional(rollbackFor = Exception.class) public void add(WorkerInfo workerInfo, UserDto userDto) { }Copy the code