在 Spring Batch 中使用 2 个数据源时面临提交问题 [英] Facing issue with commits when using 2 datasources in Spring Batch

查看:32
本文介绍了在 Spring Batch 中使用 2 个数据源时面临提交问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目进行批处理并尝试使用 2 个数据源 (oracle)(一个用于 spring 元数据,第二个用于应用程序).

My project does batch processing and is trying to use 2 datasources (oracle) (one for spring metadata and second for application).

示例配置在 github 项目 (github.com/jobas2007/spring_proj) 中,但由于配置了 2 个事务管理器/数据源,因此在为 2 个数据源完成的提交之间管理事务似乎不一致.主数据源(用于批处理)提交正确发生,但最终在 ItemWriter 中执行保存"时,在保存/更新应用程序表期间观察到非常不可预测的行为.

The sample configuration is in github project (github.com/jobas2007/spring_proj) , but because there are 2 transaction manager/datasource configured, there appears to be inconsistency in managing transaction across commits being done for 2 datasources. The Primary datasource (for batch) commits are happening correctly, but when finally doing "save" in ItemWriter,  very unpredictable behavior is observed during save/update to application tables.

请推荐一种管理多个数据源之间事务的好方法?

Please advise a good way to manage transaction between multiple datasources?

根据链接 https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/,进入步骤时Tx开始一个chunk

As per link https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/ , Tx starts for a chunk when entering step

尝试了其中一篇帖子的建议使用ChainedTransactionManager",但在布线方面面临重大问题Spring Batch中多个数据源的使用

Tried suggestion from one of the post to use 'ChainedTransactionManager' but facing major issues in wiring Use of multiple DataSources in Spring Batch

代码在github中

预期结果是具有可预测的稳健交易管理

expected result is to have predictable robust tx management

推荐答案

如果决定在 Spring Batch 中使用两个数据源,则需要使用 JtaTransactionManager 来同步 两个数据源之间的分布式事务.

If you decide to use two datasources with Spring Batch, you need to use a JtaTransactionManager to synchronize the distributed transaction between the two datasources.

您可以在此处找到 David Syer 博士关于此事的精彩文章:Spring 中的分布式事务,有和没有 XA

You can find a great article by Dr. David Syer on the matter here: Distributed transactions in Spring, with and without XA

这篇关于在 Spring Batch 中使用 2 个数据源时面临提交问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆