大纲

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. 傻妞PLUS机器人教程——安装

    特性 简单易用的消息搬运功能. 简单强大的自定义回复功能. 完整支持 ECMAScript 5.1 的插件系统,基于 otto. 支持通过内置的阉割版 Express / fetch ,接入互联网. ...

  2. ServerMmon青蛇探针,一个超好用的服务器状态监控-搭建教程

    serverMmon(青蛇探针)是nodeJs开发的一个酷炫高逼格的云探针.云监控.服务器云监控.多服务器探针~. 在线演示:http://106.126.11.114:5880/ 主要功能: 全球服 ...

  3. 使用Bioaider进行本地blast

    系统环境为windows11 1. 下载blast程序 https://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/ 双击安装,记住自己的 ...

  4. python xlrd 读取表格 单元格值被覆盖

    代码实现顺序: 按行读取 按列读取 满足if条件 单元格值赋值给字典 实现代码: datas = []# 定义一个空列表 for i in range (3,nrows): sheet_data={} ...

  5. selenium自动化测试+OCR-获取图片页面小说

    随着爬虫技术的发展,反爬虫技术也越来越高. 目前有些网站通过自定义字体库的方式实现反爬,主要表现在页面数据显示正常,但是页面获取到的实际数据是别的字符或者是一个编码.这种反爬需要解析网站自己的字体库, ...

  6. 查看oracle数据库编码格式;ORACLE数据库NLS_CHARACTERSET和NLS_NCHAR_CHARACTERSET区别

    查看Oracle数据库字符编码格式得方法,有以下两种,第二种方法有注释,第一种没有Select * from nls_database_parameter;Select * from sys.prop ...

  7. 学习 Docker 如何查看镜像信息?

    学习 Docker 如何查看镜像信息? 一.images 命令列出镜像 通过使用如下两个命令,列出本机已有的镜像: docker images 或: docker image ls 如下图所示: 对上 ...

  8. [源码系列:手写spring] IOC第十四节:容器事件和事件监听器

    代码分支 https://github.com/yihuiaa/little-spring/tree/event-and-event-listenerhttps://github.com/yihuia ...

  9. 用 PHP 封装的发送邮件类

    点击查看代码 <?php class MailSender { // 发件人邮箱地址 private $fromEmail; // 发件人名称 private $fromName; // 收件人 ...

  10. static修饰成员方法、static修饰成员的特点总结、浅聊主方法-java se进阶 day01

    1.工具类的介绍 工具类不是用于描述事物的类,而是帮我们完成事情的类(打工) 如图 当我们编写完这个类后,我们会发现一件事,这个类自己本身并没有意义,这个类完全是给用户进行调用方法的 既然是专门给用户 ...