当前位置:网站首页>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
作者声明
如有问题,欢迎指正!
边栏推荐
- 闭包和装饰器
- B+树索引页大小是如何确定的?
- Chapter6 : Has Artificial Intelligence Impacted Drug Discovery?
- The highest level of wiring in the computer room, the beauty is suffocating
- This editor actually claims to be as fast as lightning!
- JVM性能调优
- 关于容器的小案例
- 使用bat脚本以json格式导出mongo数据库中指定表数据
- Ts是什么?
- The website adds a live 2d kanban girl that can dress up and interact
猜你喜欢

组态 - 笔记

Flink本地UI运行

【回归预测-lssvm分类】基于最小二乘支持向量机lssvm实现数据分类代码

Recommended open source tools: MegPeak, a high-performance computing tool

惊艳!京东T8纯手码的Redis核心原理手册,基础与源码齐下

Flink优化

How to use Databricks for data analysis on TiDB Cloud | TiDB Cloud User Guide

Before quitting, make yourself a roll king

SQL 优化这么做就对了!

四大首搭加持,美学、安全、操控、效率优势明显,比亚迪海豹售价20.98万元起售!
随机推荐
ESP32 Repeated Reboot Issue Arduino Shield Power Outage Detector
JUC common thread pool source learning 02 ( ThreadPoolExecutor thread pool )
SQL 优化这么做就对了!
JVM performance tuning
Interface automation framework, lm-easytest beta version released, use it quickly~
Flink实时仓库-DWS层(状态编程,windowall的使用,数据保存到clickhouse)模板代码
postgresql的普通字符串和转义字符串
Could not acquire management access for administration
MySQL客户端工具的使用与MySQL SQL语句
学习 MySQL 需要知道的 28 个小技巧
Alluxio为Presto赋能跨云的自助服务能力
Redis cache penetration, breakdown, avalanche and consistency issues
一文读懂网络效应对Web3的重要意义
【元胞自动机】基于元胞自动机模拟生命演化、病毒感染等实例附matlab代码
Fink异步IO的实战(关联维表)
Mac 中 MySQL 的安装与卸载
Understand Chisel language. 28. Chisel advanced finite state machine (2) - Mealy state machine and comparison with Moore state machine
1700. 无法吃午餐的学生数量
闭包和装饰器
去腾讯面试,直接让人出门左拐 :幂等性都不知道!