前言
使用seata,以目前最新的坐标版本来看
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2021.1</version>
</dependency>

其内部seata相关的依赖仅为seata-spring-boot-starter,可知其是整体功能的起始点
以seata目前最新的发布版本1.4.2来分析下的源码:GitHub
模块介绍

分为两部分:
- seata-server:事务协调器(TC),独立进程执行
- seata-spring:spring体系下相关使用模块(此篇讲解部分)
配置
模块对应的目录结构如下

可见spring.factories

- SeataPropertiesAutoConfiguration 初始化默认配置参数
- SeataDataSourceAutoConfiguration 处理datasource(两个方面:BeanPostProcessor、ProxyCreator)
- SeataAutoConfiguration 全局事务扫描及设置
- HttpAutoConfiguration 配置拦截器及异常处理器WebMvcConfigurerAdapter
重点关注SeataAutoConfiguration

-
DefaultFailureHandlerImpl 失败处理
-
GlobalTransactionScanner 事务扫描器
扫描

GlobalTransactionScanner继承自AbstractAutoProxyCreator
AbstractAutoProxyCreator:自动代理生成器,为符合条件的bean设置代理



至此含有注解(TwoPhaseBusinessAction、GlobalTransactional、GlobalLock)的bean就被设置了拦截器
拦截器
GlobalTransactionalInterceptor


方法触发时拦截对应的执行信息(GlobalTransactional、GlobalLock注解情况),根据注解类型不同进行不同的逻辑处理
以GlobalTransactional类型为例

采用的是:设计模式行为型-命令模式
主要任务:对执行的方法子事务进行管理

详见TransactionalTemplate.execute
TccActionInterceptor
同GlobalTransactionalInterceptor触发模式

事务具体的执行交由ActionInterceptorHandler进行处理
类关系图

网友评论