分布式事务解决方案之Seata
2020-06-04 06:41
211 查看
1 . 下载seata(事务协调器TC)服务器
下载地址: https://github.com/seata/seata/releases/dowrpoadv0.7.1/seata-server-0.7.1.zip
也可以直接解压:资料lseata-server-0.7.1.zip
2 . 解压并 启动
cdm 打开 start F:\seata\seata-server-0.7.1\bin\seata-server.bat -p 8888 -m file
**注**:其中8888为服务端口号; file为启动模式,这里指seata服务将采用文件的方式存储信息。
3 . 父工程导入alibaba框架(使用seata工具必须基于alibaba框架)
<!--alibaba框架配置--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
4 . 配置TM和RM
- 1 。服务消费者 和 服务提供者 导入seata架包
<!--seata配置--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-seata</artifactId> <version>2.1.0.RELEASE</version> </dependency>
- 2。服务消费者 和 服务提供者 配置数据源
spring: application: name: order-service #服务名称 datasource: #seata数据源代理配置 ds0: url: jdbc:mysql://localhost:3306/mb?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC username: root password: root type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver
- 3。服务消费者 和 服务提供者 获取数据源
@Configuration public class DatabaseConfiguration { private final ApplicationContext applicationContext; public DatabaseConfiguration(ApplicationContext applicationContext){ this.applicationContext = applicationContext; } @Bean @ConfigurationProperties(prefix ="spring.datasource.ds0" ) public DruidDataSource ds0(){ DruidDataSource druidDataSource = new DruidDataSource(); return druidDataSource; } @Primary @Bean public DataSource dataSource(DruidDataSource ds0) { DataSourceProxy pds0 = new DataSourceProxy(ds0); return pds0; } }
- 4。 导入 file.conf 和 registry.conf( 在seata-server-0.7.1\conf目录下 )
file.conf ,registry.conf 及 数据源获取 放置路径如下:
- 设置file.conf 更改服务名 和 端口号 即可
6. 开启分布式事务事务
全局事务发起者
分支事务
注意:全局事务 和 分支事务配置一样(导入seata架包,配置数据源,获取数据源,导入file.conf 和 registry.conffile.conf 更改服务名 和 端口号即可)。。。。。项目运行必须开启事务协调器TC(打开cdm输入: start (seata在电脑中的解压路径)/seata-server-0.7.1\bin\seata-server.bat -p 8888 -m file )
相关文章推荐
- 分布式事务解决方案Seata(Fescar)--记录个人学习的过程
- 开源的分布式事务解决方案之Seata
- 分布式事务解决方案,中间件 Seata 的设计原理详解
- 分布式系统事务一致性解决方案
- 分布式事务解决方案教学视频
- 深入理解分布式事务,高并发下分布式事务的解决方案
- 分布式系统事务一致性解决方案大对比,谁最好使?
- 微服务架构的分布式事务解决方案
- 分布式系统事务一致性解决方案
- GTS来了!阿里微服务架构下的分布式事务解决方案
- 分布式系统事务一致性解决方案
- Spring Alibaba Cloud使用Seata实现分布式事务,Nacos作为配置中心(一)
- 聊聊分布式事务,再说说解决方案
- 深入解读微服务架构下分布式事务解决方案
- 微服务架构的分布式事务解决方案[转]
- 分布式事务之消息补偿解决方案
- 深入解读微服务架构下分布式事务解决方案
- 分布式事务解决方案
- 深入理解分布式事务,高并发下分布式事务的解决方案
- 一行代码,保障分布式事务一致性—GTS:微服务架构下分布式事务解决方案