我正在尝试在春季批处理作业中提交jms和数据库事务。我假设spring batch事务是xa事务。但在我的项目写入器中,即使jms事务出错,数据库事务也在提交。如果我遗漏了什么,谁能帮帮我?我需要在spring batch中为XA使用第三方库吗?
发布于 2020-05-21 11:06:32
我实际上是故意抛出异常来测试事务回滚。现在,即使没有任何jms事务,只有一个数据库事务正在提交,即使从项抛出异常,writer.Below是编写器中的方法,它将保存到数据库中。compEvent对象是注入到该类中的jpa仓库。
private void writeCEs(Map<TrueEvent, List<Event>> agentMap)
throws FailedCompensationException, Exception {
for (Entry<TrueEvent, List<Event>> agent : agentMap.entrySet()) {
agent.getValue().stream().forEach((ce) -> {
compEvent.save(ce);
});
updateRecordFileStatus(agent.getKey());
//postToAccounting(agent.getKey(), agent.getValue());
}
throw new Exception("Testing XA roolback.... ");
}下面是我的批量配置
@EnableBatchProcessing @EnableTransactionManagement @Configuration @ComponentScan({“com..*”})
公共类TrueBatchConfig扩展了DefaultBatchConfigurer {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Autowired
EventReader reader;
@Autowired
private EventProcessor processor;
@Autowired
private EventWriter writer;
@Bean
protected Step step1(ThreadPoolTaskExecutor executor) {
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setPropagationBehavior(Propagation.REQUIRED.value());
attribute.setIsolationLevel(Isolation.DEFAULT.value());
attribute.setTimeout(30);
return steps.get("step1").<List<TrueEvent>, Map<TrueUpEvent, List<Event>>>chunk(10).reader(reader)
.processor(processor).writer(writer).transactionAttribute(attribute).build();
}
@Bean(name = "firstBatchJob")
public Job job(@Qualifier("step1") Step step1) {
return jobs.get("firstBatchJob").start(step1).build();
}}
https://stackoverflow.com/questions/61902080
复制相似问题