春季批处理中可以有一个jobRepository来使用本地事务,但在分布式XA事务中执行特定的作业步骤?
对于 XA,我使用 Atomicos 3.8.0。步骤应该读取 JMS 消息并在处理后更新数据库。
spring配置的相关部分:
<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>