当前位置:网站首页>Small Tools (4) integrated Seata1.5.2 distributed transactions
Small Tools (4) integrated Seata1.5.2 distributed transactions
2022-08-03 16:08:00 【Zheng Qing】
文章目录
一、前言
- springboot 2.7.0
- springcloudalibaba 2021.0.1.0
- seata1.5.2
二、docker-compose部署seata
tips: Remember to modify the corresponding configuration yourself
git clone https://gitee.com/zhengqingya/docker-compose.git
cd docker-compose/Liunx/seata/1.5.2
# 修改seata配置文件`./seata-server/resources/application.yml`
# 修改`docker-compose-seata.yml`相关IP配置
# nacos命名空间`prod`下新建配置`seata-server.properties`
# 新建数据库`seata-server`,导入sql脚本`./sql/seata-server.sql`
# 运行
docker-compose -f docker-compose-seata.yml -p seata up -d
# 进入容器
# docker exec -it seata-server sh
# 查看日志
docker logs -f seata-server
访问seata控制台:ip地址:7091
The login account password is default:seata/seata
部分配置文件
Liunx/seata/1.5.2/docker-compose-seata.yml
# 可参考 https://seata.io/zh-cn/docs/ops/deploy-by-docker-compose.html
version: '3'
# 网桥 -> 方便相互通讯
networks:
seata:
driver: bridge
services:
seata:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/seata-server:1.5.2 # 原镜像`seataio/seata-server:1.5.2`
container_name: seata-server # 容器名为'seata-server'
restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- "./seata-server/resources/application.yml:/seata-server/resources/application.yml"
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
# 注册到nacos上的ip.客户端将通过该ip访问seata服务.
# 注意公网ip和内网ip的差异.
SEATA_IP: www.zhengqingya.com
# 指定seata服务启动端口
SEATA_PORT: 8091
ports: # 映射端口
- "7091:7091"
- "8091:8091"
networks:
- seata
Liunx/seata/1.5.2/seata-server/resources/application.yml
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${
user.home}/logs/seata
console:
user:
username: seata
password: seata
seata:
config:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: prod
username: nacos
password: nacos
data-id: seata-server.properties
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: prod
cluster: default
username: nacos
password: nacos
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
Liunx/seata/1.5.2/nacos-config/seata-server.properties
# 可参考 https://github.com/seata/seata/blob/develop/script/config-center/config.txt
# 存储模式
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
# 需要根据mysql的版本调整driverClassName
# mysql8及以上版本对应的driver:com.mysql.cj.jdbc.Driver
# mysql8以下版本的driver:com.mysql.jdbc.Driver
store.db.driverClassName=com.mysql.jdbc.Driver
# 注意根据生产实际情况调整参数host和port
store.db.url=jdbc:mysql://www.zhengqingya.com:3306/seata-server?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
# 数据库用户名
store.db.user=root
# 用户名密码
store.db.password=root
# Transaction routing rules configuration, only for the client
service.vgroupMapping.default_tx_group=default
service.vgroupMapping.my_test_tx_group=default
service.vgroupMapping.user-tx-group=default
service.vgroupMapping.order-tx-group=default
service.vgroupMapping.demo-tx-group=default
service.vgroupMapping.system-tx-group=default
三、springcloud引入seata
tips: Xiaobian here willseataA common module is extracted separately,提供给used by business modules
1、引入seata依赖
outermost parentpom.xml中统一管理seata版本
<dependencyManagement>
<dependencies>
<!-- seata分布式事务 -->
<!-- https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
</dependencyManagement>
seata模块中引入
<dependencies>
<!-- outermost parentpom.xml中统一管理seata版本 -->
<!-- seata -->
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-seata -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/io.seata/seata-spring-boot-starter -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</dependency>
</dependencies>
2、application-seata.yml
# seata配置
seata:
# 是否开启seata
enabled: true
# Seata 应用编号,默认为 ${spring.application.name}
application-id: ${
spring.application.name}
# Seata 事务组编号,用于 TC 集群名
tx-service-group: ${
spring.application.name}-tx-group
# 自动代理
enable-auto-data-source-proxy: true
# 服务配置项
# service:
# # 虚拟组和分组的映射
# vgroup-mapping:
# test-tx-group: default
# # 分组和 Seata 服务的映射
# grouplist:
# default: 127.0.0.1:8091
config:
type: nacos
nacos:
serverAddr: ${
spring.cloud.nacos.config.server-addr}
group: SEATA_GROUP
namespace: ${
spring.cloud.nacos.config.namespace}
username: ${
spring.cloud.nacos.config.username}
password: ${
spring.cloud.nacos.config.password}
dataId: seata-server.properties
registry:
type: nacos
nacos:
application: seata-server
server-addr: ${
spring.cloud.nacos.config.server-addr}
group: SEATA_GROUP
namespace: ${
spring.cloud.nacos.config.namespace}
username: ${
spring.cloud.nacos.config.username}
password: ${
spring.cloud.nacos.config.password}
# See data source configuration:application-db.yml
spring:
datasource:
dynamic:
seata: true # 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
3、undo_log.sql
tips: 在要使用seataCreate a table under a distributed transaction database
undo_log.sql
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,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
4、used by business modulesseata
引入seata
<dependency>
<groupId>com.zhengqing</groupId>
<artifactId>seata</artifactId>
</dependency>
5、@GlobalTransactional
Use annotations in the main entry@GlobalTransactional
实现分布式事务
本文案例demo源码
https://gitee.com/zhengqingya/small-tools.git
今日分享语句:
If you want to be successful in this world,When you enter a certain salon,You have to let your vanity pay homage to the vanity of others.
边栏推荐
- 【Unity入门计划】基本概念(7)-Input Manager&Input类
- 为教育插上数字化的翅膀,网易云信发布「互联网+教育」整体解决方案
- 13、OOM模拟
- 人脸识别损失函数的汇总 | Pytorch版本实现
- 请问大家,MySQL全量怎么样可以提高性能呢?我这里瓶颈是在Source上,在不增加并行度的情况下,
- 新一代网状网协议T-Mesh无线通信技术优势介绍
- [微信小程序开发者工具] × #initialize
- Difference and performance comparison between HAL and LL library of STM32
- JS handwritten call apply bind (detailed) (interview)
- How much does Ark Survival Evolved cost?
猜你喜欢
基于DMS的数仓智能运维服务,知多少?
MATLAB gcf图窗保存图像,黑色背景/透明背景
ECCV 2022 | 基于关系查询的时序动作检测方法
【Unity入门计划】基本概念(7)-Input Manager&Input类
土耳其国防部:联合协调中心将对首艘乌克兰粮船进行安全检查
Js array method is summarized
美国国防部更“青睐”光量子系统研究路线
Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil
为什么我强烈推荐使用智能化async?
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
随机推荐
【Unity入门计划】制作RubyAdventure01-玩家的创建&移动
【899. 有序队列】
Neural networks, cool?
JS基础--判断
方舟生存进化开服需要多少钱
Fortinet产品导入AWS AMI操作文档
Basic knowledge points in js - events
一文看懂推荐系统:召回01:基于物品的协同过滤(ItemCF),item-based Collaboration Filter的核心思想与推荐过程
自定SvgIcon公用组件
在 360 度绩效评估中应该问的 20 个问题
基于牛顿方法在直流微电网潮流研究(Matlab代码实现)
聊聊这个SaaS领域爆火的话题
Windows服务器如何防止黑客入侵的安全设置
CopyOnWriteArrayList详解
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
【码蹄集新手村600题】将一个函数定义宏
6000 字+,帮你搞懂互联网架构演变历程!
使用VS Code搭建ESP-IDF环境
MATLAB gcf图窗保存图像,黑色背景/透明背景
瞌睡检测系统介绍