- 浏览: 1325048 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (896)
- spring4 (14)
- hibernate3 (26)
- spring2 (35)
- struts2 (55)
- struts1 (15)
- 设计模式 (15)
- java (172)
- mybatis3 (11)
- sql (17)
- mysql (13)
- jbpm (10)
- J2EE (45)
- tools (29)
- js (83)
- 数据结构 (13)
- Html (26)
- web (22)
- flex (33)
- Oracle (57)
- linux (49)
- 算法 (6)
- 其它 (12)
- easyui (1)
- bootstrap (13)
- xml (2)
- tomcat (1)
- redis (10)
- activemq (2)
- webservice (11)
- maven (2)
- springboot (1)
- ubuntu (1)
- python (14)
- rocketmq (1)
- springcloud (10)
- opencv (1)
最新评论
-
mike_eclipse:
Hashtable是线程不安全的吗?好像是线程安全的吧?
多线程之集合类 -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
lodop打印控件 -
xingcxb:
经过测试,假的,依旧会出现中文乱码!!!!store方法里面采 ...
java 读写Properties文件,不会出现中文乱码 -
tiger20111989:
...
Spring注解方式管理事务 -
zw7534313:
...
js 文字上下滚动 无间断循环显示
1.seata-server1.5.2下载
https://seata.io/zh-cn/blog/download.html
在你的mysql数据库中创建名为seata的库
/script/server/db/mysql.sql
2.在你的参与全局事务的数据库中加入undo_log这张表
CREATE TABLE IF NOT EXISTS `undo_log`
(
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) NOT NULL COMMENT 'global transaction id',
`context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
`log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
3.在你的项目中引入seata依赖
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</exclusion>
</exclusions>
</dependency>
<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>
4.application.yml
seata:
enabled: true
application-id: orders-service
tx-service-group: default-tx-group
config:
type: nacos
nacos:
namespace: 0ef84c31-0570-4591-a708-1945a253048d
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
username: "nacos"
password: "nacos"
data-id: seataServer.properties
registry:
type: nacos
nacos:
application: seata-server
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: 0ef84c31-0570-4591-a708-1945a253048d
username: "nacos"
password: "nacos"
data-source-proxy-mode: AT
5.运行你下载的nacos,并参考https://github.com/seata/seata/tree/develop/script/config-center 的config.txt并修改
命名空间:SEATA_GROUP
DATAID: service.vgroupMapping.default-tx-group
DATAID: seataServer.properties
service.vgroupMapping.default-tx-groupneirong内容:
default
seataServer.propertiesneirong内容如下:
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none
#Transaction routing rules configuration, only for the client
service.vgroupMapping.default-tx-group=default
#If you use a registry, you can ignore it
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h
#Log rule configuration, for client and server
log.exceptionRate=100
#Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
store.publicKey=
#If `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
#连接数据库要修改
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=abc
store.db.password=1000
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
#These configurations are required if the `store mode` is `redis`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100
#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false
#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
6.在全局事务调用者(发起全局事务的服务)的接口上加入@GlobalTransactional
@RequestMapping("/save")
@GlobalTransactional(lockRetryInternal = 10,lockRetryTimes = 30)
public Boolean save(@RequestBody Orders orders) {
return ordersService.save(orders);
}
7.其它知识:
执行阶段:
- 可回滚:根据 SQL 解析结果,记录回滚日志
- 持久化:回滚日志和业务 SQL 在同一个本地事务中提交到数据库
完成阶段:
- 分支提交:异步删除回滚日志记录
- 分支回滚:依据回滚日志进行反向补偿更新
其实XA流程相对AT模式,是简单许多
AT: 解析sql生成undolog+竞争全局锁(rpc)
https://seata.io/zh-cn/blog/download.html
在你的mysql数据库中创建名为seata的库
/script/server/db/mysql.sql
2.在你的参与全局事务的数据库中加入undo_log这张表
CREATE TABLE IF NOT EXISTS `undo_log`
(
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) NOT NULL COMMENT 'global transaction id',
`context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
`log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
3.在你的项目中引入seata依赖
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</exclusion>
</exclusions>
</dependency>
<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>
4.application.yml
seata:
enabled: true
application-id: orders-service
tx-service-group: default-tx-group
config:
type: nacos
nacos:
namespace: 0ef84c31-0570-4591-a708-1945a253048d
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
username: "nacos"
password: "nacos"
data-id: seataServer.properties
registry:
type: nacos
nacos:
application: seata-server
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: 0ef84c31-0570-4591-a708-1945a253048d
username: "nacos"
password: "nacos"
data-source-proxy-mode: AT
5.运行你下载的nacos,并参考https://github.com/seata/seata/tree/develop/script/config-center 的config.txt并修改
命名空间:SEATA_GROUP
DATAID: service.vgroupMapping.default-tx-group
DATAID: seataServer.properties
service.vgroupMapping.default-tx-groupneirong内容:
default
seataServer.propertiesneirong内容如下:
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none
#Transaction routing rules configuration, only for the client
service.vgroupMapping.default-tx-group=default
#If you use a registry, you can ignore it
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h
#Log rule configuration, for client and server
log.exceptionRate=100
#Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
store.publicKey=
#If `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
#连接数据库要修改
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=abc
store.db.password=1000
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
#These configurations are required if the `store mode` is `redis`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100
#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false
#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
6.在全局事务调用者(发起全局事务的服务)的接口上加入@GlobalTransactional
@RequestMapping("/save")
@GlobalTransactional(lockRetryInternal = 10,lockRetryTimes = 30)
public Boolean save(@RequestBody Orders orders) {
return ordersService.save(orders);
}
7.其它知识:
执行阶段:
- 可回滚:根据 SQL 解析结果,记录回滚日志
- 持久化:回滚日志和业务 SQL 在同一个本地事务中提交到数据库
完成阶段:
- 分支提交:异步删除回滚日志记录
- 分支回滚:依据回滚日志进行反向补偿更新
其实XA流程相对AT模式,是简单许多
AT: 解析sql生成undolog+竞争全局锁(rpc)
发表评论
-
springcloud之服务网关gateway结合nacos
2023-08-05 15:49 7331.gateway application.yml配置 spr ... -
springcloud之链路追踪zipkin
2023-08-05 15:35 14701.java -jar zipkin-server-2.23. ... -
sentinel 1.8.5 server搭建
2023-08-05 10:44 12861.下载sentinel-dashboard-1.8.5.ja ... -
springcloud之分布式事务seata-server搭建
2023-08-05 10:38 29651.分布式事务seata-server-1.5.2 2.co ... -
Loadbalancer随机负载均衡策略
2023-08-05 10:23 6461.loadbalencer 负载算法默认询改为随机 默认负 ... -
springcloud之openfeign集成sentinel限流
2023-08-05 10:07 13741.先调用服务接口,才会在sentinel显示应用名称 2. ... -
springcloud之服务调用openfeign
2023-08-05 09:57 12711.springcloud之使用openfeign调用各子服务 ... -
Nacos配置中心
2023-08-05 09:50 13541.可以将其他应用的配置信息存储在nacos 2. ... -
将应用注册到Nacos
2023-08-05 09:42 31281.nacos2.0.4 服务注册与发现 <de ... -
搭建Nacos Server
2023-08-05 09:30 12011.nacos server搭建 2.nacos-serve ...
相关推荐
AT模式是Seata提供的四种事务模式之一,它是Automatic Transaction模式的简称,适用于大部分读写场景,尤其是对性能有较高要求的业务。 在AT模式下,Seata通过代理SQL执行,自动地将一次分布式事务转化为两个阶段的...
Seata 提供了AT(Automatic Two-Phase Commit)、TCC(Try-Confirm-Cancel)、Saga 和 XA 四种分布式事务模式。其中,AT模式是最常用的,它通过记录undo日志并在事务结束时进行提交或回滚,实现了类似两阶段提交的...
seata 1.5.2
Seata将ACID(原子性、一致性、隔离性、持久性)事务特性扩展到了分布式环境,通过全局事务服务(Global Transaction Service,GTS)实现跨服务的分布式事务处理,确保数据的一致性。 Feign是Spring Cloud生态中的...
Seata支持AT、TCC、SAGA和XA四种事务模式,其中AT模式是最常见的,适用于大部分业务场景。Seata通过全局事务ID(GTID)来跟踪整个分布式事务,并在事务提交或回滚时协调所有参与的服务。 **4. 微服务架构** 微服务...
1、详细介绍了Seata阿里分布式事务中间件; 2、对整个分布式事务解决方案原理进行了详细的分析,包括tcc、xa、saga等解决方案 3、IT老齐老师视频资料配套pdf;
项目中集成seata(分布式事务解决方案)
在Seata的AT模式(Automatic Transaction Mode)中,事务分为两个阶段: 1. **Try阶段**:每个服务执行本地事务,如果都成功则进入下一阶段。 2. **Commit/Cancel阶段**:TC根据所有服务的反馈决定是提交还是回滚...
1. 在seata 1.4.2 分布式事务AT模式示例的基础上增加TCC模式; 2. 目前采用的是AT模式和TCC模式混合使用的方式; 3. Account模块采用了TCC模式,整合业务代码; 4. Product模块采用了TCC模式,未整合业务代码; 5. ...
基于Java+txlcn+seata的分布式事务实现案例源码.zip ## txlcn 测试步骤 ### 准备工作 - 启动 MySQL Redis - 创建数据库 tx-manager txlcn-a txlcn-b txlcn-c - 在库 tx-manager 中执行 t_tx_exception.sql 创建...
(十三)SpringCloudAlibaba-Seata(分布式事务使用)附本章代码及Seata压缩包
1. 项目idea+maven+spring-boot+spring-cloud+spring-cloud-alibaba,依赖nacos 2.0.1, mysql,seata server 1.4.2; 2. 示例包括三个服务,订单服务,商品服务,账户服务; 3. 创建订单的同时,需要扣减商品库存,并...
而Seata(Simple Extensible Autonomous Transaction Architecture)则是一个高性能、轻量级的开源分布式事务解决方案,它旨在解决微服务环境下的分布式事务问题。本篇文章将详细探讨如何在Spring Cloud项目中整合...
Seata是一个开源的分布式事务解决方案,用于解决分布式系统中的事务一致性问题。它提供了高性能和高可靠性的分布式事务支持,可以在微服务架构中保证数据的一致性和可靠性。 Seata的核心概念包括三个组件:事务协调...
此代码为我的Seata专栏的配套代码,主要是Seata的AT模式和TCC模式的基本使用代码。 1. 包含seata-order-8001和seata-stock-8002两个服务 2. 包含两个数据库seata-order和seata-stock对应的表的sql结构和数据 3. ...
seata1.5.1和seata1.5.2安装包 seata1.5.1和seata1.5.2安装包 seata1.5.1和seata1.5.2安装包
采用前后端分离的模式,微服务版本前端(基于 RuoYi-Vue)。后端采用Spring Boot、Spring Cloud & ...流量控制框架选型Sentinel,分布式事务选型Seata。提供了技术栈(Vue3 Element Plus Vite)版本RuoYi-Cloud-Vue3
本课程将深入探讨分布式事务管理框架Seata的核心概念和实际应用。学员将了解Seata在微服务架构中的作用、原理及实践,包括分布式事务、一致性、可靠性等方面的重要知识点。 视频大小:16.6G
Seata是一个开源的分布式事务解决方案,提供了AT、TCC、SAGA、XA等多种事务模式。Seata的原理分析可以分为三个部分:资源管理、事务管理和通信管理。资源管理负责管理分布式事务中的资源,事务管理负责管理事务的...
1. AT模式:这是Seata的主要工作模式,它通过代理数据库操作,将一个分布式事务转化为两个本地事务,即自动提交和回滚事务。在事务开始时记录undo log(回滚日志),在事务提交时执行提交操作,如果出现异常则根据...