大纲

1.seata-samples的配置文件和启动类

2.seata-samples业务服务启动时的核心工作

3.seata-samples库存服务的连接池配置

4.Seata对数据库连接池代理配置的分析

5.Dubbo RPC通信过程中传递全局事务XID

6.Seata跟Dubbo整合的Filter(基于SPI机制)

7.seata-samples的AT事务例子原理流程

8.Seata核心配置文件file.conf的内容介绍

1.seata-samples的配置文件和启动类

(1)seata-samples的测试步骤

(2)seata-samples用户服务的配置和启动类

(3)seata-samples库存服务的配置和启动类

(4)seata-samples订单服务的配置和启动类

(5)seata-samples业务服务的配置和启动类

示例仓库:

https://github.com/seata/seata-samples

示例代码的模块ID:seata-samples-dubbo

(1)seata-samples的测试步骤

步骤一:启动DubboAccountServiceStarter

步骤二:启动DubboStorageServiceStarter

步骤三:启动DubboOrderServiceStarter

步骤四:运行DubboBusinessTester

(2)seata-samples用户服务的配置和启动类

dubbo-account-service.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 把jdbc.properties文件里的配置加载进来 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean> <!-- 将配置文件里的值注入到库存服务的数据库连接池accountDataSource中 -->
<bean name="accountDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.account.url}"/>
<property name="username" value="${jdbc.account.username}"/>
<property name="password" value="${jdbc.account.password}"/>
<property name="driverClassName" value="${jdbc.account.driver}"/>
<property name="initialSize" value="0"/>
<property name="maxActive" value="180"/>
<property name="minIdle" value="0"/>
<property name="maxWait" value="60000"/>
<property name="validationQuery" value="Select 'x' from DUAL"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="25200000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800"/>
<property name="logAbandoned" value="true"/>
<property name="filters" value="mergeStat"/>
</bean> <!-- 创建数据库连接池代理,通过DataSourceProxy代理accountDataSourceProxy数据库连接池 -->
<bean id="accountDataSourceProxy" class="io.seata.rm.datasource.DataSourceProxy">
<constructor-arg ref="accountDataSource"/>
</bean> <!-- 将数据库连接池代理accountDataSourceProxy注入到JdbcTemplate数据库操作组件中-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="accountDataSourceProxy"/>
</bean> <dubbo:application name="dubbo-demo-account-service">
<dubbo:parameter key="qos.enable" value="false"/>
</dubbo:application>
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:protocol name="dubbo" port="20881"/>
<dubbo:service interface="io.seata.samples.dubbo.service.AccountService" ref="service" timeout="10000"/> <!-- 将JdbcTemplate数据库操作组件注入到AccountServiceImpl中 -->
<bean id="service" class="io.seata.samples.dubbo.service.impl.AccountServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean> <!-- 全局事务注解扫描组件 -->
<bean class="io.seata.spring.annotation.GlobalTransactionScanner">
<constructor-arg value="dubbo-demo-account-service"/>
<constructor-arg value="my_test_tx_group"/>
</bean>
</beans>

启动类:

public class DubboAccountServiceStarter {
//Account service is ready. A buyer register an account: U100001 on my e-commerce platform
public static void main(String[] args) {
ClassPathXmlApplicationContext accountContext = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-account-service.xml"}
);
accountContext.getBean("service");
JdbcTemplate accountJdbcTemplate = (JdbcTemplate)accountContext.getBean("jdbcTemplate");
accountJdbcTemplate.update("delete from account_tbl where user_id = 'U100001'");
accountJdbcTemplate.update("insert into account_tbl(user_id, money) values ('U100001', 999)");
new ApplicationKeeper(accountContext).keep();
}
} //The type Application keeper.
public class ApplicationKeeper {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationKeeper.class);
private final ReentrantLock LOCK = new ReentrantLock();
private final Condition STOP = LOCK.newCondition(); //Instantiates a new Application keeper.
public ApplicationKeeper(AbstractApplicationContext applicationContext) {
addShutdownHook(applicationContext);
} private void addShutdownHook(final AbstractApplicationContext applicationContext) {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
try {
applicationContext.close();
LOGGER.info("ApplicationContext " + applicationContext + " is closed.");
} catch (Exception e) {
LOGGER.error("Failed to close ApplicationContext", e);
} LOCK.lock();
try {
STOP.signal();
} finally {
LOCK.unlock();
}
}
}));
} public void keep() {
LOCK.lock();
try {
LOGGER.info("Application is keep running ... ");
STOP.await();
} catch (InterruptedException e) {
LOGGER.error("ApplicationKeeper.keep() is interrupted by InterruptedException!", e);
} finally {
LOCK.unlock();
}
}
}

(3)seata-samples库存服务的配置和启动类

dubbo-stock-service.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 把jdbc.properties文件里的配置加载进来 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean> <!-- 将配置文件里的值注入到库存服务的数据库连接池stockDataSource中 -->
<bean name="stockDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.stock.url}"/>
<property name="username" value="${jdbc.stock.username}"/>
<property name="password" value="${jdbc.stock.password}"/>
<property name="driverClassName" value="${jdbc.stock.driver}"/>
<property name="initialSize" value="0"/>
<property name="maxActive" value="180"/>
<property name="minIdle" value="0"/>
<property name="maxWait" value="60000"/>
<property name="validationQuery" value="Select 'x' from DUAL"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="25200000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800"/>
<property name="logAbandoned" value="true"/>
<property name="filters" value="mergeStat"/>
</bean> <!-- 创建数据库连接池代理,通过DataSourceProxy代理stockDataSource数据库连接池 -->
<bean id="stockDataSourceProxy" class="io.seata.rm.datasource.DataSourceProxy">
<constructor-arg ref="stockDataSource"/>
</bean> <!-- 将数据库连接池代理stockDataSourceProxy注入到JdbcTemplate数据库操作组件中-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="stockDataSourceProxy"/>
</bean> <dubbo:application name="dubbo-demo-stock-service">
<dubbo:parameter key="qos.enable" value="false"/>
</dubbo:application>
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:protocol name="dubbo" port="20882"/>
<dubbo:service interface="io.seata.samples.dubbo.service.StockService" ref="service" timeout="10000"/> <!-- 将JdbcTemplate数据库操作组件注入到StockServiceImpl中 -->
<bean id="service" class="io.seata.samples.dubbo.service.impl.StockServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean> <!-- 全局事务注解扫描组件 -->
<bean class="io.seata.spring.annotation.GlobalTransactionScanner">
<constructor-arg value="dubbo-demo-stock-service"/>
<constructor-arg value="my_test_tx_group"/>
</bean>
</beans>

启动类:

//The type Dubbo stock service starter.
public class DubboStockServiceStarter {
//Stock service is ready. A seller add 100 stock to a sku: C00321
public static void main(String[] args) {
ClassPathXmlApplicationContext stockContext = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-stock-service.xml"}
);
stockContext.getBean("service");
JdbcTemplate stockJdbcTemplate = (JdbcTemplate)stockContext.getBean("jdbcTemplate");
stockJdbcTemplate.update("delete from stock_tbl where commodity_code = 'C00321'");
stockJdbcTemplate.update("insert into stock_tbl(commodity_code, count) values ('C00321', 100)");
new ApplicationKeeper(stockContext).keep();
}
}

(4)seata-samples订单服务的配置和启动类

dubbo-order-service.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 把jdbc.properties文件里的配置加载进来 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean> <!-- 将配置文件里的值注入到库存服务的数据库连接池orderDataSource中 -->
<bean name="orderDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.order.url}"/>
<property name="username" value="${jdbc.order.username}"/>
<property name="password" value="${jdbc.order.password}"/>
<property name="driverClassName" value="${jdbc.order.driver}"/>
<property name="initialSize" value="0"/>
<property name="maxActive" value="180"/>
<property name="minIdle" value="0"/>
<property name="maxWait" value="60000"/>
<property name="validationQuery" value="Select 'x' from DUAL"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="25200000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800"/>
<property name="logAbandoned" value="true"/>
<property name="filters" value="mergeStat"/>
</bean> <!-- 创建数据库连接池代理,通过DataSourceProxy代理stockDataSource数据库连接池 -->
<bean id="orderDataSourceProxy" class="io.seata.rm.datasource.DataSourceProxy">
<constructor-arg ref="orderDataSource"/>
</bean> <!-- 将数据库连接池代理orderDataSourceProxy注入到JdbcTemplate数据库操作组件中-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="orderDataSourceProxy"/>
</bean> <dubbo:application name="dubbo-demo-order-service">
<dubbo:parameter key="qos.enable" value="false"/>
</dubbo:application>
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:protocol name="dubbo" port="20883"/>
<dubbo:service interface="io.seata.samples.dubbo.service.OrderService" ref="service" timeout="10000"/>
<dubbo:reference id="accountService" check="false" interface="io.seata.samples.dubbo.service.AccountService"/> <!-- 将JdbcTemplate数据库操作组件注入到OrderServiceImpl中 -->
<bean id="service" class="io.seata.samples.dubbo.service.impl.OrderServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
<property name="accountService" ref="accountService"/>
</bean> <!-- 全局事务注解扫描组件 -->
<bean class="io.seata.spring.annotation.GlobalTransactionScanner">
<constructor-arg value="dubbo-demo-order-service"/>
<constructor-arg value="my_test_tx_group"/>
</bean>
</beans>

启动类:

//The type Dubbo order service starter.
public class DubboOrderServiceStarter {
//The entry point of application.
public static void main(String[] args) {
//Order service is ready . Waiting for buyers to order
ClassPathXmlApplicationContext orderContext = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-order-service.xml"}
);
orderContext.getBean("service");
new ApplicationKeeper(orderContext).keep();
}
}

(5)seata-samples业务服务的配置和启动类

dubbo-business.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <dubbo:application name="dubbo-demo-app">
<dubbo:parameter key="qos.enable" value="false"/>
<dubbo:parameter key="qos.accept.foreign.ip" value="false"/>
<dubbo:parameter key="qos.port" value="33333"/>
</dubbo:application>
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:reference id="orderService" check="false" interface="io.seata.samples.dubbo.service.OrderService"/>
<dubbo:reference id="stockService" check="false" interface="io.seata.samples.dubbo.service.StockService"/> <bean id="business" class="io.seata.samples.dubbo.service.impl.BusinessServiceImpl">
<property name="orderService" ref="orderService"/>
<property name="stockService" ref="stockService"/>
</bean> <!-- 全局事务注解扫描组件 -->
<bean class="io.seata.spring.annotation.GlobalTransactionScanner">
<constructor-arg value="dubbo-demo-app"/>
<constructor-arg value="my_test_tx_group"/>
</bean>
</beans>

启动类:

//The type Dubbo business tester.
public class DubboBusinessTester {
//The entry point of application.
public static void main(String[] args) {
//The whole e-commerce platform is ready, The buyer(U100001) create an order on the sku(C00321) , the count is 2
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-business.xml"}
);
//模拟调用下单接口
final BusinessService business = (BusinessService)context.getBean("business");
business.purchase("U100001", "C00321", 2);
}
}

2.seata-samples业务服务启动时的核心工作

BusinessService业务服务启动时,会创建两个服务接口的动态代理。一个是OrderService订单服务接口的Dubbo动态代理,另一个是StockService库存服务接口的Dubbo动态代理。BusinessService业务服务的下单接口会添加@GlobalTransaction注解,通过@GlobalTransaction注解开启一个分布式事务,Seata的内核组件GlobalTransactionScanner就会扫描到这个注解。

//The type Dubbo business tester.
public class DubboBusinessTester {
//The entry point of application.
public static void main(String[] args) {
//The whole e-commerce platform is ready , The buyer(U100001) create an order on the sku(C00321) , the count is 2
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-business.xml"}
);
//模拟调用下单接口
final BusinessService business = (BusinessService)context.getBean("business");
business.purchase("U100001", "C00321", 2);
}
} public class BusinessServiceImpl implements BusinessService {
private static final Logger LOGGER = LoggerFactory.getLogger(BusinessService.class);
private StockService stockService;
private OrderService orderService;
private Random random = new Random(); @Override
@GlobalTransactional(timeoutMills = 300000, name = "dubbo-demo-tx")//分布式事务如果5分钟还没跑完,就是超时
public void purchase(String userId, String commodityCode, int orderCount) {
LOGGER.info("purchase begin ... xid: " + RootContext.getXID());
stockService.deduct(commodityCode, orderCount);
orderService.create(userId, commodityCode, orderCount);
if (random.nextBoolean()) {
throw new RuntimeException("random exception mock!");
}
} //Sets stock service.
public void setStockService(StockService stockService) {
this.stockService = stockService;
} //Sets order service.
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
}

3.seata-samples库存服务的连接池配置

首先会把jdbc.properties文件里的配置加载进来,然后将配置配置的值注入到库存服务的数据库连接池,接着通过Seata的DataSourceProxy对数据库连接池进行代理。

一.启动类

//The type Dubbo stock service starter.
public class DubboStockServiceStarter {
//Stock service is ready. A seller add 100 stock to a sku: C00321
public static void main(String[] args) {
ClassPathXmlApplicationContext stockContext = new ClassPathXmlApplicationContext(
new String[] {"spring/dubbo-stock-service.xml"}
);
stockContext.getBean("service");
JdbcTemplate stockJdbcTemplate = (JdbcTemplate)stockContext.getBean("jdbcTemplate");
stockJdbcTemplate.update("delete from stock_tbl where commodity_code = 'C00321'");
stockJdbcTemplate.update("insert into stock_tbl(commodity_code, count) values ('C00321', 100)");
new ApplicationKeeper(stockContext).keep();
}
}

二.dubbo-stock-service.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 把jdbc.properties文件里的配置加载进来 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean> <!-- 将配置文件里的值注入到库存服务的数据库连接池stockDataSource中 -->
<bean name="stockDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.stock.url}"/>
<property name="username" value="${jdbc.stock.username}"/>
<property name="password" value="${jdbc.stock.password}"/>
<property name="driverClassName" value="${jdbc.stock.driver}"/>
<property name="initialSize" value="0"/>
<property name="maxActive" value="180"/>
<property name="minIdle" value="0"/>
<property name="maxWait" value="60000"/>
<property name="validationQuery" value="Select 'x' from DUAL"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="25200000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="1800"/>
<property name="logAbandoned" value="true"/>
<property name="filters" value="mergeStat"/>
</bean> <!-- 创建数据库连接池代理,通过DataSourceProxy代理stockDataSource数据库连接池 -->
<bean id="stockDataSourceProxy" class="io.seata.rm.datasource.DataSourceProxy">
<constructor-arg ref="stockDataSource"/>
</bean> <!-- 将数据库连接池代理stockDataSourceProxy注入到JdbcTemplate数据库操作组件中-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="stockDataSourceProxy"/>
</bean>
<dubbo:application name="dubbo-demo-stock-service">
<dubbo:parameter key="qos.enable" value="false"/>
</dubbo:application>
<dubbo:registry address="zookeeper://localhost:2181" />
<dubbo:protocol name="dubbo" port="20882"/>
<dubbo:service interface="io.seata.samples.dubbo.service.StockService" ref="service" timeout="10000"/> <!-- 将JdbcTemplate数据库操作组件注入到StockServiceImpl中 -->
<bean id="service" class="io.seata.samples.dubbo.service.impl.StockServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean> <!-- 全局事务注解扫描组件 -->
<bean class="io.seata.spring.annotation.GlobalTransactionScanner">
<constructor-arg value="dubbo-demo-stock-service"/>
<constructor-arg value="my_test_tx_group"/>
</bean>
</beans>

三.jdbc.properties文件文件

jdbc.account.url=jdbc:mysql://localhost:3306/seata
jdbc.account.username=root
jdbc.account.password=123456
jdbc.account.driver=com.mysql.jdbc.Driver
# stock db config
jdbc.stock.url=jdbc:mysql://localhost:3306/seata
jdbc.stock.username=root
jdbc.stock.password=123456
jdbc.stock.driver=com.mysql.jdbc.Driver
# order db config
jdbc.order.url=jdbc:mysql://localhost:3306/seata
jdbc.order.username=root
jdbc.order.password=123456
jdbc.order.driver=com.mysql.jdbc.Driver

4.Seata对数据库连接池代理配置的分析

数据库连接池代理DataSourceProxy,会注入到JdbcTemplate数据库操作组件中。这样库存或者订单服务就可以通过Spring数据库操作组件JdbcTemplate,向Seata数据库连接池代理DataSourceProxy获取一个数据库连接。然后通过数据库连接,把SQL请求发送给MySQL进行处理。

5.Dubbo RPC通信过程中传递全局事务XID

BusinessService对StockService进行RPC调用时,会传递全局事务XID。StockService便可以根据RootContext.getXID()获取到全局事务XID。

public class BusinessServiceImpl implements BusinessService {
private static final Logger LOGGER = LoggerFactory.getLogger(BusinessService.class);
private StockService stockService;
private OrderService orderService;
private Random random = new Random(); @Override
@GlobalTransactional(timeoutMills = 300000, name = "dubbo-demo-tx")//分布式事务如果5分钟还没跑完,就是超时
public void purchase(String userId, String commodityCode, int orderCount) {
LOGGER.info("purchase begin ... xid: " + RootContext.getXID());
stockService.deduct(commodityCode, orderCount);
orderService.create(userId, commodityCode, orderCount);
if (random.nextBoolean()) {
throw new RuntimeException("random exception mock!");
}
}
...
} public class StockServiceImpl implements StockService {
private static final Logger LOGGER = LoggerFactory.getLogger(StockService.class);
private JdbcTemplate jdbcTemplate; @Override
public void deduct(String commodityCode, int count) {
LOGGER.info("Stock Service Begin ... xid: " + RootContext.getXID());
LOGGER.info("Deducting inventory SQL: update stock_tbl set count = count - {} where commodity_code = {}", count, commodityCode); jdbcTemplate.update("update stock_tbl set count = count - ? where commodity_code = ?", new Object[] {count, commodityCode});
LOGGER.info("Stock Service End ... ");
}
...
}

6.Seata跟Dubbo整合的Filter(基于SPI机制)

Seata与Dubbo整合的Filter过滤器ApacheDubboTransactionPropagationFilter会将向SeataServer注册的全局事务xid,设置到RootContext中。

7.seata-samples的AT事务例子原理流程

8.Seata核心配置文件file.conf的内容介绍

# Seata网络通信相关的配置
transport {
# 网络通信的类型是TCP
type = "TCP"
# 网络服务端使用NIO模式
server = "NIO"
# 是否开启心跳
heartbeat = true
# 是否允许Seata的客户端批量发送请求
enableClientBatchSendRequest = true
# 使用Netty进行网络通信时的线程配置
threadFactory {
bossThreadPrefix = "NettyBoss"
workerThreadPrefix = "NettyServerNIOWorker"
serverExecutorThread-prefix = "NettyServerBizHandler"
shareBossWorker = false
clientSelectorThreadPrefix = "NettyClientSelector"
clientSelectorThreadSize = 1
clientWorkerThreadPrefix = "NettyClientWorkerThread"
# 用来监听和建立网络连接的Boss线程的数量
bossThreadSize = 1
# 默认的Worker线程数量是8
workerThreadSize = "default"
}
shutdown {
# 销毁服务端的时候的等待时间是多少秒
wait = 3
}
# 序列化类型是Seata
serialization = "seata"
# 是否开启压缩
compressor = "none"
} # Seata服务端相关的配置
service {
# 分布式事务的分组
vgroupMapping.my_test_tx_group = "default"
# only support when registry.type=file, please don't set multiple addresses
default.grouplist = "127.0.0.1:8091"
# 是否开启降级
enableDegrade = false
# 是否禁用全局事务
disableGlobalTransaction = false
} # Seata客户端相关的配置
client {
# 数据源管理组件的配置
rm {
# 异步提交缓冲区的大小
asyncCommitBufferLimit = 10000
# 锁相关的配置:重试间隔、重试次数、回滚冲突处理
lock {
retryInterval = 10
retryTimes = 30
retryPolicyBranchRollbackOnConflict = true
}
reportRetryCount = 5
tableMetaCheckEnable = false
reportSuccessEnable = false
}
# 事务管理组件的配置
tm {
commitRetryCount = 5
rollbackRetryCount = 5
}
# 回滚日志的配置
undo {
dataValidation = true
logSerialization = "jackson"
logTable = "undo_log"
}
# log日志的配置
log {
exceptionRate = 100
}
}

Seata源码—2.seata-samples项目介绍的更多相关文章

  1. 元旦在家撸了两天Seata源码,你们是咋度过的呢?

    撸Seata源码 2020年12月31日晚23点30分,我发了2020年的最后一个朋友圈:假期吃透Seata源码,有组队的吗? 不少小伙伴都来点赞了, 其中也包括Seata项目的发起人--季敏大佬哦! ...

  2. Seata源码分析(一). AT模式底层实现

    目录 GlobalTransactionScanner 继承AbstractAutoProxyCreator 实现InitializingBean接口 写在最后 以AT为例,我们使用Seata时只需要 ...

  3. 【seata源码学习】001 - seata-server的配置读取和服务注册

    github, seata vergilyn seata-fork seata.io zh-cn docs (PS. 随缘看心情写,坚持不了几天.文章还是写的超级的烂,排版也奇差无比~~~~ 脑壳疼~ ...

  4. 调式源码解决 seata 报错 can not get cluster name 问题

    最近在使用Spring Cloud整合分布式事务seata,项目启动之后,控制台一直报错: can not get cluster name in registry config 'service.v ...

  5. Hadoop源码学习笔记之NameNode启动场景流程一:源码环境搭建和项目模块及NameNode结构简单介绍

    最近在跟着一个大佬学习Hadoop底层源码及架构等知识点,觉得有必要记录下来这个学习过程.想到了这个废弃已久的blog账号,决定重新开始更新. 主要分以下几步来进行源码学习: 一.搭建源码阅读环境二. ...

  6. Spring源码系列(一)--详解介绍bean组件

    简介 spring-bean 组件是 IoC 的核心,我们可以通过BeanFactory来获取所需的对象,对象的实例化.属性装配和初始化都可以交给 spring 来管理. 针对 spring-bean ...

  7. Amazium源码分析:(1)基本介绍

    前言 Amazium是一个网格系统的框架,分析该源码的目的是了解网格系统的实现. 网格系统 定义:设计美观页面布局的方式,上图能够很直观的了解什么是网格系统. 基本概念 column: 列. gutt ...

  8. Heritrix源码分析(七) Heritrix总体介绍(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/642794         本博客已迁移到本人独立博客: http://www.yun ...

  9. 使用Maven将Hadoop2.2.0源码编译成Eclipse项目

    编译环境: OS:RHEL 6.3 x64 Maven:3.2.1 Eclipse:Juno SR2 Linux x64 libprotoc:2.5.0 JDK:1.7.0_51 x64 步骤: 1. ...

  10. 通过go-ethereum源码看如何管理项目

    今天抽空看了下go-ethereum项目的源码 ( https://github.com/ethereum/go-ethereum ),其中 ethereum 是github下的一个帐号.go-eth ...

随机推荐

  1. Mybatis 返回自增主键的id

    Mybatis 返回自增主键的idkeyProperty=id:封装到对象中的id字段当中keyColumn=id:封装到数据库的id这一列order=AFTER:在新增语句之后执行 方法一 < ...

  2. 火爆的 幻兽帕鲁/Palworld 单机➕联机 电脑游戏 免费畅游

    在广阔的世界中收集神奇的生物"帕鲁",派他们进行战斗.建造.做农活,工业生产等,这是一款支持多人游戏模式的全新开放世界生存制作游戏. ▼补丁主要内容 ・修复加载世界数据时,加载画面 ...

  3. spring - [01] 简介

    Spring发展至今,已经形成了一个生态体系(Spring全家桶) 001 || Spring 定义   Spring是一款主流的Java EE轻量级开源框架,目的是用于简化Java企业级应用的开发难 ...

  4. 云服务器Linux 时间与本地时间不一致

      云服务器Linux 时间与本地时间不一致 问题解释: 云服务器和本地计算机之间的时间不一致可能是因为它们使用的时间同步服务不同,或者云服务器没有配置自动对时. 解决方法: 手动同步时间:可以使用d ...

  5. C#之 Dictionary 详解

    基本概念 Dictionary<TKey, TValue>是C#中用于存储键值对集合的泛型类,属于System.Collections.Generic命名空间.它允许使用键(Key)来访问 ...

  6. FastAPI性能优化指南:参数解析与惰性加载

    扫描二维码关注或者微信搜一搜:编程智域 前端至全栈交流与成长 探索数千个预构建的 AI 应用,开启你的下一个伟大创意 第一章:参数解析性能原理 1.1 FastAPI请求处理管线 async def ...

  7. sudo: unable to resolve host xxxx: Name or service not known

    前言 在 Linux 环境中,我使用 sudo 执行命令,发生报错:sudo: unable to resolve host xxxx: Name or service not known 解决 这个 ...

  8. 什么!你还不会写Vue组件,编写《功能级权限》匹配公式组件

    说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...

  9. Ollama系列05:Ollama API 使用指南

    本文是Ollama系列教程的第5篇,在前面的4篇内容中,给大家分享了如何再本地通过Ollama运行DeepSeek等大模型,演示了chatbox.CherryStudio等UI界面中集成Ollama的 ...

  10. jupyter -- 数据分析可视化开发工具

    博客地址:https://www.cnblogs.com/zylyehuo/ jupyter介绍 jupyter就是anaconda提供的一个基于浏览器的可视化开发工具 jupyter的基本使用 启动 ...