Use of Steata distributed transactions

The use scenario of Steata distributed transactions is a back-end management system where the amount of concurrency is not very large.
Steate introduces and uses the official website: http://seata.io/zh-cn/docs/overview/what-is-seata.html
The distributed transaction solution we use here is the AT mode, which is the 2pc mode
we use It is version 0.7.1. Different versions may use different ways.

  • seata wants to control distributed transactions

  • 1) Every microservice database must create a uodo_log table
    – note that 0.7.1+ adds the field context
    CREATE TABLE undo_log(
    idbigint(20) NOT NULL AUTO_INCREMENT,
    branch_idbigint(20) NOT NULL,
    xidvarchar(100) NOT NULL,
    contextvarchar (128) NOT NULL,
    rollback_infolongblob NOT NULL,
    log_statusint(11) NOT NULL,
    log_createddatetime NOT NULL,
    log_modifieddatetime NOT NULL,
    PRIMARY KEY ( id),
    UNIQUE KEY ux_undo_log( xid, branch_id)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
    Insert picture description here

  • 2), install the transaction coordinator seata-server https://github.com/seata.seata/releases
    Insert picture description here
    registry.conf registry configuration modification registry type=nacos, the address is changed to the connection address of nacos.
    Insert picture description here
    Then start the service

  • 3) Integration
    1. Import dependency spring-cloud-starter-alibaba-seata | seata-all-0.7.1

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
  • 3. All microservices that want to use distributed transactions use seata DataSourceProxy
@Configuration
public class MySeataConfig {
    
    

    @Autowired
    DataSourceProperties dataSourceProperties;

    @Bean
    public DataSource dataSource(DataSourceProperties dataSourceProperties) {
    
    
        HikariDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
        if (StringUtils.hasText(dataSourceProperties.getName())) {
    
    
            dataSource.setPoolName(dataSourceProperties.getName());
        }
        return new DataSourceProxy(dataSource);
    }
}

  • 4. Import
    registry.conf for each service.
    Insert picture description here
    The service.vgroup_mapping configuration of file.conf file.conf must be
    set consistent with spring.application.name: vgroup_mapping.gulimall-order-fescar-service-group = "default", or Modify the suffix by configuring spring.cloud.alibaba.seata.tx-service-group, but it must be consistent with the configuration in file.conf
    Insert picture description here
  • 5. Big transaction: @GlobalTransactional
  • 6. Remote small transactions: @Transactional
    is used at the entrance of @Transactional , while other remote calls to open transactions are local transactions @Transactional.
    Insert picture description here

Guess you like

Origin blog.csdn.net/u014496893/article/details/114238773