[英]Spring batch and XA and local transactions
It is possible to have a jobRepository in spring batch to use local transactions but execute particular job steps in distributed XA transaction? 春季批处理中可能有一个jobRepository以使用本地事务,但是在分布式XA事务中执行特定的作业步骤?
For XA I use Atomicos 3.8.0. 对于XA,我使用Atomicos 3.8.0。 Step is supposed to read the JMS message and update the DB after processing.
步骤应该在处理后读取JMS消息并更新DB。
The relevant part of spring configuration: 弹簧配置的相关部分:
<job id="job" xmlns="http://www.springframework.org/schema/batch">
<step id="inventorySync">
<tasklet transaction-manager="xaTransactionManager">
<chunk reader="jmsQueueReader"
processor="messageProcessor"
writer="dbWriter"
reader-transactional-queue="true"/>
</tasklet>
</step>
</job>
<bean id="xaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"
lazy-init="true" depends-on="inventoryDataSource">
<constructor-arg name="transactionManager" ref="userTransactionManager"/>
<constructor-arg name="userTransaction" ref="userTransaction"/>
<property name="allowCustomIsolationLevels" value="true"/>
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="batchJobsDataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseType" value="${batch.data.source.type}"/>
</bean>
<jdbc:embedded-database id="batchJobsDataSource" type="HSQL"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="batchJobsDataSource"/>
</bean>
I have used an XA transaction across all 3 of those resources before successfully using Bitronix in unit testing and WebSphere JTA in production. 在成功在单元测试中使用Bitronix和在生产中使用WebSphere JTA之前,我已经在所有这三种资源中使用了XA事务。 If you have a separate transaction manager for the Batch Database from the rest of your step, you risk the step and batch database being 'out-of-sync' in the event of a failure in either one of the places (batch database or step).
如果在其余步骤中有单独的批处理数据库事务管理器,则在以下任何一个位置(批处理数据库或步骤)发生故障的情况下,都有可能使步骤和批处理数据库“不同步” )。
for example, you may have a successful commit on your step (JMS and DB) and then failure on your batch Database. 例如,您可能在步骤(JMS和DB)上成功提交,然后在批处理数据库上失败。 when you restart your job it will think that a certain step was unsuccessful whilst your underlying execution was.
当您重新开始工作时,它会认为某个步骤不成功,而您的基础执行却失败了。 covering all 3 of the resources in the same transaction manager will prevent this.
在同一个事务管理器中覆盖所有3个资源将防止这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.