preface
Have to say that seata distributed transaction or a lot of the pit, and a lot of online solutions to stay in the old version, and you use the new version of cause a lot of problems need to be trample, I spent a day access to success, success sorting out one by one piece of the latest recommended version 1.4.0 ali seata distributed transaction access, will provide a network backup behind the address, We directly download the required information from me to avoid a series of problems such as access failure due to the inconsistency of version and information
I. Project version
Because my project also access LCN, so all support LCN, SEATA distributed transaction, if you want to know ABOUT LCN read the article I wrote before
<java.version>1.8</java.version>
<spring.boot.version>2.29..RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
<spring.cloud.alibaba.version>2.2. 0.RELEASE</spring.cloud.alibaba.version>
<mysql-connector-java.version>8.019.</mysql-connector-java.version>
<pagehelper-spring-boot.version>1.213.</pagehelper-spring-boot.version>
<lombok.version>1.1812.</lombok.version>
<lcn.version>5.02..RELEASE</lcn.version>
<dubbo.version>2.76.</dubbo.version>
<seata.version>1.4. 0</seata.version>
Copy the code
Two, environment building: Windows
1. Prepare the database
Ali demanded a seata library,The above three tables are the table data required by Ali in the library, respectively branch transaction, global transaction, global lock. Since Ali’s Seata is not a two-stage process in the traditional sense, the exact principle is not explained here
2. Prepare seata Server and Config files (important)
Because I am connected to NACOS, there are many steps needed. Other access methods will not be introduced here
First you should have the following script from the official website to synchronize your relevant data toNacos configuration centerThen, downloadseata-serverRegistry – conf files
Registry {# file, NACOS, Eureka, Redis, ZK, Consul, ETCD3, SOFAtype = "nacos"
nacos {
application = "serverAddr"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"}} config {# file, nacos, Apollo, Zk, Consul, etcd3type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
app.id = "seata-server"
apollo.meta = "http://192.168.1.204:8801"
namespace = "application"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"}}Copy the code
This is the configuration registered to NACOS, so I won’t bother with that file.conf file. The following are the key steps, because I think the above use is no problem, no pits.Before starting Seata-Server, synchronize the config file to nacOSModify the config.txt aboveSave the changes and then Windows needs to start in the GitBase interfaceOn the current path page, right-click and select the gitbase command
Run sh nacos-config.sh 127.0.0.1 until it appearsCheck whether nacOS is synchronized to the configuration center
Start seata-Server and check whether the NACOS service list has been successfully registered
Iii. Project source code
The project structure
Starting the service if the following occurs represents successful registration with the SEATA CoordinatorStart the showDemonstrate what went wrongI’m not going to show you how to insert data, but I think it’s pretty clear here
Access to distributed access code and information, have been put on Github, you can download
Github.com/huyufan1995…
Welcome to follow my wechat official account [Village of the Apes]! To talk about Java interview and my wechat further communication and learning, wechat mobile search [codeYuanzhicunup] can be added if there are related technical problems welcome to leave a message to discuss, the public number is mainly used for technology sharing, including often meet test analysis, as well as source code interpretation, micro service framework, technical hot spots, etc..