原理
TM两阶段:
阶段1:TM向TC申请全局事务,netty客户端发起了一次记录xid的请求
阶段2:TC协调之后,决定执行RM是否提交或者回滚。
spring公共组件部分
1、SeataAutoConfiguration类加载
利用springboot自动装配机制从spring.factories文件加载自动配置类SeataAutoConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.seata.spring.boot.autoconfigure.SeataAutoConfiguration@ConditionalOnProperty(prefix = SEATA_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
@AutoConfigureAfter({SeataCoreAutoConfiguration.class})
public class SeataAutoConfiguration {private static final Logger LOGGER = LoggerFactory.getLogger(SeataAutoConfiguration.class);@Bean(BEAN_NAME_FAILURE_HANDLER)@ConditionalOnMissingBean(FailureHandler.class)public FailureHandler failureHandler() {return new DefaultFailureHandlerImpl();}@Bean@DependsOn({BEAN_NAME_SPRING_APPLICATION_CONTEXT_PROVIDER, BEAN_NAME_FAILURE_HANDLER})@ConditionalOnMissingBean(GlobalTransactionScanner.class)public GlobalTransactionScanner globalTransactionScanner(SeataProperties seataProperties, FailureHandler failureHandler,ConfigurableListableBeanFactory beanFactory,@Autowired(required = false) List<ScannerChecker> scannerCheckers) {if (LOGGER.isInfoEnabled()) {LOGGER.info("Automatically configure Seata");}// set bean factoryGlobalTransactionScanner.setBeanFactory(beanFactory);// add checkers// '/META-INF/services/io.seata.spring.annotation.ScannerChecker'GlobalTransactionScanner.addScannerCheckers(EnhancedServiceLoader.loadAll(ScannerChecker.class));// spring beansGlobalTransactionScanner.addScannerCheckers(scannerCheckers);// add scannable packagesGlobalTransactionScanner.addScannablePackages(seataProperties.getScanPackages());// add excludeBeanNamesGlobalTransactionScanner.addScannerExcludeBeanNames(seataProperties.getExcludesForScanning());// create global transaction scannerreturn new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(), failureHandler);}
}