当前位置:网站首页>SEATA分布式事务
SEATA分布式事务
2022-07-30 14:40:00 【努力学习,努力爱你!】
官方地址
http://seata.io/zh-cn/index.html
参考官网即可
使用
1
每个微服务都需要创建 UNDO_LOG 表
SEATA AT 模式需要 UNDO_LOG 表
-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
2
下载seata服务器
从 https://github.com/seata/seata/releases,下载服务器软件包,将其解压缩。
3
导入依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
4
registry.conf 注册中心配置文件
file.conf Seata配置
nacos中的seata的注册名字是serveraddr
5
每个服务使用seata 代理数据源
package com.jhj.gulimall.product.config;
import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
@Configuration
public class MySeataConfig {
@Autowired
DataSourceProperties dataSourceProperties;
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties){
HikariDataSource build = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
if (StringUtils.hasText(dataSourceProperties.getName())){
build.setPoolName(dataSourceProperties.getName());
}
return new DataSourceProxy(build);
}
}
6
每个微服务将 file.conf register.conf放到resource下
修改每一个file.conf的service.vgroup_mapping 修改为service.vgroup_mapping.${spring.application.name}-fescar-service-group
方式一直接修改file.conf
方式二 配置yml
spring:
cloud:
alibaba:
seata:
tx-service-group: ${
spring.application.name}
启动测试
想要做分布式事务的大事务入口方法上加上 @GlobalTransactional 远程调用的小事务 @Transactional
作者声明
如有问题,欢迎指正!
边栏推荐
- Alluxio为Presto赋能跨云的自助服务能力
- [机缘参悟-53]:《素书》-3-修身养志[求人之志章第三]
- 1700. 无法吃午餐的学生数量
- ESP32 Repeated Reboot Issue Arduino Shield Power Outage Detector
- 分布式前修课:MySQL实现分布式锁
- Why did I switch from developer to testing, 3 years software testing engineer, tell you the secret of this
- 关于mariadb/mysql的user表:密码正确但登录失败,可能与mysql的空用户有关
- 关于容器的小案例
- Flink实时数仓完结
- 吃透Chisel语言.29.Chisel进阶之通信状态机(一)——通信状态机:以闪光灯为例
猜你喜欢

打破原则引入SQL,MongoDB到底想要干啥?

About the data synchronization delay of MySQL master-slave replication

Understand the Chisel language. 29. Chisel advanced communication state machine (1) - communication state machine: take the flash as an example

Smart Contract Security - Private Data Access

5. DOM

JVM性能调优

算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面

ToDesk版本更新,引入RTC传输技术,是否早以替代向日葵远程控制?

Use of SLF4J

组态 - 笔记
随机推荐
Metaverse Post Office AI space-themed series of digital collections will be launched at 10:00 on July 30th "Yuanyou Digital Collection"
Lock wait timeout exceeded解决方案
ToDesk版本更新,引入RTC传输技术,是否早以替代向日葵远程控制?
软件包 - 笔记
About the data synchronization delay of MySQL master-slave replication
JUC common thread pool source learning 02 ( ThreadPoolExecutor thread pool )
canal scrape data
分布式前修课:MySQL实现分布式锁
SQL 优化这么做就对了!
Android jump to google app market
Meta首份元宇宙白皮书9大看点,瞄准80万亿美元市场
localhost with 127.0.0.1
71-page comprehensive overall solution for global tourism 2021 ppt
新时代背景下智慧城市的建设与5G技术有何关联
面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全
Excel使用Visual Basic Editor对宏进行修改
canal抓取数据
Kubernetes应用管理深度剖析
国内数字藏品的乱象与未来
Why did I switch from developer to testing, 3 years software testing engineer, tell you the secret of this