Because Seata’s specific installation varies from framework to framework, some of the installation steps or configurations in this article are specific to the Nacos Spring Cloud framework and MySQL database, as well as specific versions of individual frameworks.

Install the Seata server

Step 1: Run the file in the database

V1.4.2 seata/script/server/db/mysql. The SQL

After running, the database has the following tables:

The name of the table instructions
global_table Global transaction
branch_table Branch of the transaction
lock_table Global lock

Step 2: Download the installation package and decompress it

Official Download linkGithub.com/seata/seata…

Step 3: Modify the decompressed configuration file

Open the file conf/file.conf

Modify mode and database connection information

Step 4: Modify the decompressed registration file

Open the file conf/registry.conf

Modify the type and nacos information

Step 5: Run the startup script

Run the script bin/seata-server.bat

You can see the service in NACOS after successful startup

Install the Seata client

Step 1: Run the SQL file in the database

V1.4.2 seata/script/client/at/db

After running, the database has the following tables:

The name of the table instructions
undo_log

Step 2: Add dependencies to the MAVEN project

. <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> The < spring. The boot. Version > 2.6.3 < / spring. The boot. Version > < spring. Cloud. Version > 2021.0.1 < / spring. Cloud. Version > "Alibaba. Cloud. Version > 2021.0.1.0 < / alibaba. Cloud. Version > < spring - the cloud - starter - alibaba - seata. Version > 2021.0.1.0 < / spring - the cloud - starter - alibaba - seata. Version > < seata - spring - the boot - starter. Version > 1.4.2 < / seata - spring - the boot - starter. Version > < / properties > < dependencyManagement > <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring.boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring.cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${alibaba.cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <! -- Spring boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <! -- Spring Cloud --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency> <! -- Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <! -- Seata --> <dependency> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> <version>${seata-spring-boot-starter.version}</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <version>${spring-cloud-starter-alibaba-seata.version}</version> <exclusions> <exclusion> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <! <id> AliyunMaven </id> <name> AliyunMaven </name> <url>https://maven.aliyun.com/repository/central</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ...Copy the code

Step 3: Modify the bootstrap.yml file

Spring: application: # service name: xxxx-serviceCopy the code

Step 4: Modify the application.yml file

Discovery: server-addr: 127.0.0.1:8848 Alibaba: seata: discovery: server-addr: 127.0.0.1:8848 Tx-service-group: seata-tx-service-group seata: data-source-proxy-mode: AT config: Nacos: server-addr: 127.0.0.1:8848 group: "DEFAULT_GROUP"Copy the code

Step 5: Modify the NACOS configuration list

Data id Configure the content
service.vgroupMapping.seata-tx-service-group seata-tx-service-group
service.seata-tx-service-group.grouplist 127.0.0.1:8091

Use Seata distributed transactions

Customize the Spring Boot startup class as required

@EnableDiscoveryClient @EnableAutoConfiguration @SpringBootApplication public class ExampleApplication { public static void main(String[] args) { SpringApplication.run(ExampleApplication.class); }}Copy the code

Scenarios requiring distributed transactions are annotated with GlobalTransactiona annotations

@GlobalTransactional(rollbackFor = Exception.class) public xxxx xxxx(...) {... }Copy the code

After the client is successfully started, the following logs are displayed

Register TM Success. Client Version :1.4.2, Server Version :1.4.2...Copy the code

Resources and links

  • Seata.io/zh-CN /docs/…
  • View the framework version description github.com/alibaba/spr…