企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
:-: ![](https://img.kancloud.cn/e3/a0/e3a080d9b07d0a481e24daa1b458a990_1732x940.png) 架构图 在课件代码中已经提供了对应的模块,如下图: ![](https://img.kancloud.cn/b0/2c/b02cf0938a548bd58875c98ff5d24332_1189x89.png) (1)三个模块都已经被注册到nacos中。 (2)通过order模块下单(即order模块为访问入口),order模块通过openfeign调用storage模块进行库存操作,order模块通过openfeign调用account模块进行账户金额操作。 <br/> 具体的模块创建过程这里就不一一赘述了,下面主要是讲与seata相关的一些配置。 **1. 三个模块都要添加seata相关依赖** ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <exclusions> <exclusion> <artifactId>seata-all</artifactId> <groupId>io.seata</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> <version>1.0.0</version><!--版本最好与安装得的seata版本一致--> </dependency> ... ``` **2. 三个模块都要设置seata的事务组名称** *`application.yml`* ```yml spring: cloud: alibaba: seata: tx-service-group: fsp_tx_group #seata事务组名称 #它就是seata安装目录的 %SEATA_HOME%\conf\file.conf 文件中的vgroup_mapping.my_test_tx_group属性值 ``` **3. 三个模块都要配置`resources/file.conf`配置文件** ![](https://img.kancloud.cn/3c/6c/3c6ca1c37ce8d7f8e953d24e531a3905_1232x232.png) 三个模块的`file.conf`配置内容都是一样的,如下: ```conf service { #transaction service group mapping #这里设置的事务组名称是个性的,即可以自由定义该属性名称,可以与其他模块相同也可以不同 #fsp_tx_group是seata安装目录的 %SEATA_HOME%\conf\file.conf 文件中的vgroup_mapping.my_test_tx_group属性值 vgroup_mapping.fsp_tx_group = "default" #only support when registry.type=file, please don't set multiple addresses default.grouplist = "127.0.0.1:8091" #disable seata disableGlobalTransaction = false } ## transaction log store, only used in seata-server store { ## store mode: file、db mode = "db" ## file store property file { ## store location dir dir = "sessionStore" } ## database store property db { ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc. datasource = "dbcp" ## mysql/oracle/h2/oceanbase etc. db-type = "mysql" driver-class-name = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/seata" user = "root" password = "root" } } ``` **4. 三个模块都要配置`resources/registry.conf`配置文件** ![](https://img.kancloud.cn/3c/6c/3c6ca1c37ce8d7f8e953d24e531a3905_1232x232.png) 三个模块的`registry.conf`配置内容都是一样的,如下: ```conf registry { # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "nacos" nacos { serverAddr = "localhost:8848" namespace = "" cluster = "default" } 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、etcd3 type = "file" nacos { serverAddr = "localhost" namespace = "" } consul { serverAddr = "127.0.0.1:8500" } apollo { app.id = "seata-server" apollo.meta = "http://192.168.1.204:8801" } zk { serverAddr = "127.0.0.1:2181" session.timeout = 6000 connect.timeout = 2000 } etcd3 { serverAddr = "http://localhost:2379" } file { name = "file.conf" } } ```