提交 b1fc258a 编写于 作者: zlt2000's avatar zlt2000

更新seata-demo的代码,适配seata1.3

上级 9c53c5ee
## **详细的原理和部署细节请查看**
[Spring Cloud同步场景分布式事务怎样做?试试Seata](https://mp.weixin.qq.com/s/0yCmHzlXDC9BkbUuEt0_fQ)
 
## 测试环境
* mysql 5.7
* seata 1.3
* nacos 1.3
> **注意**:如果nacos使用低于1.3的版本不需要配置username和password;如果使用1.3以上版本必需开启 `nacos.core.auth.enabled=true` 并且配置username和password,否则读取不到seata-server
 
## 配置中心的配置如下
**config.txt**
```properties
service.vgroupMapping.test_tx_service_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.url=jdbc:mysql://192.168.28.130:3306/seata?useUnicode=true
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
```
>根据自己的环境修改 url、user、password 配置值
## 说明
 
## seata的配置如下
**registry.conf**
```json
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.28.130:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "192.168.28.130:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
```
 
## 说明
**包括以下5个模块,分别是**
* `business-service`:业务服务
......
......@@ -4,8 +4,20 @@ spring:
username: root
password: 1q2w3e4r
driver-class-name: com.mysql.cj.jdbc.Driver
cloud:
alibaba:
seata:
# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应,默认是${spring.application.name}-fescar-service-group
tx-service-group: account-service-group
\ No newline at end of file
seata:
tx-service-group: test_tx_service_group
config:
type: nacos
nacos:
serverAddr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
\ No newline at end of file
......@@ -4,7 +4,10 @@ server:
spring:
application:
name: account-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
server-addr: 192.168.28.130:8848
\ No newline at end of file
server-addr: 192.168.28.130:8848
username: nacos
password: nacos
\ No newline at end of file
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
spring:
cloud:
alibaba:
seata:
# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应,默认是${spring.application.name}-fescar-service-group
tx-service-group: business-service-group
\ No newline at end of file
seata:
tx-service-group: test_tx_service_group
config:
type: nacos
nacos:
serverAddr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
\ No newline at end of file
......@@ -4,7 +4,15 @@ server:
spring:
application:
name: business-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
server-addr: 192.168.28.130:8848
\ No newline at end of file
server-addr: 192.168.28.130:8848
username: nacos
password: nacos
ribbon:
ConnectTimeout: 100000
ReadTimeout: 1000000
OkToRetryOnAllOperations: false
\ No newline at end of file
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
......@@ -4,8 +4,20 @@ spring:
username: root
password: 1q2w3e4r
driver-class-name: com.mysql.cj.jdbc.Driver
cloud:
alibaba:
seata:
# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应,默认是${spring.application.name}-fescar-service-group
tx-service-group: order-service-group
\ No newline at end of file
seata:
tx-service-group: test_tx_service_group
config:
type: nacos
nacos:
serverAddr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
\ No newline at end of file
......@@ -4,7 +4,10 @@ server:
spring:
application:
name: order-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
server-addr: 192.168.28.130:8848
\ No newline at end of file
server-addr: 192.168.28.130:8848
username: nacos
password: nacos
\ No newline at end of file
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
......@@ -9,6 +9,17 @@
<artifactId>seata-demo</artifactId>
<description>seata分布式事务demo</description>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<!-- 业务服务(TM) -->
<module>business-service</module>
......
......@@ -4,8 +4,20 @@ spring:
username: root
password: 1q2w3e4r
driver-class-name: com.mysql.cj.jdbc.Driver
cloud:
alibaba:
seata:
# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应,默认是${spring.application.name}-fescar-service-group
tx-service-group: storage-service-group
\ No newline at end of file
seata:
tx-service-group: test_tx_service_group
config:
type: nacos
nacos:
serverAddr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.server-addr}
group: SEATA_GROUP
username: nacos
password: nacos
\ No newline at end of file
......@@ -4,7 +4,10 @@ server:
spring:
application:
name: storage-service
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
server-addr: 192.168.28.130:8848
\ No newline at end of file
server-addr: 192.168.28.130:8848
username: nacos
password: nacos
\ No newline at end of file
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "192.168.28.130"
namespace = "public"
cluster = "default"
}
file {
name = "file.conf"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册