春季批处理-整个工作的一笔交易 [英] Spring batch - One transaction over whole Job

查看:78
本文介绍了春季批处理-整个工作的一笔交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring-Batch 执行批处理,该批处理在数据库中创建了一些对象,从这些对象中创建了一个文件,然后将该文件发送到FTP服务器.

I am using Spring-Batch to execute a batch that creates some objects in the database, creates a file from these objects and then sends the file to a FTP server.

因此,我有2个步骤:一个从DB读取conf,将其插入DB并创建文件;第二个将文件发送到FTP服务器.

Thus, I have 2 steps : One that reads conf from DB, insert into the DB and creates the file ; the second sends the file to the FTP server.

问题是FTP服务器出现问题时,我无法回滚事务(以取消向数据库中插入的新内容).

The problem is when there is a problem with the FTP server, I can't rollback the transaction (to cancel the new inserts into the DB).

如何配置作业以在不同步骤中仅使用一项事务?

推荐答案

由于spring-batch的事务性质,这是一个坏主意.
恕我直言,一种简单的解决方案应该是使用作业开始时生成的令牌标记第1步中保存的数据,如果您的FTP上传失败,请转到清除步骤以使用令牌删除所有数据.

This is a bad idea due to transactional nature of spring-batch.
IMHO a simple solution should be to mark data saved in step 1 with a token generated when job starts and, if your FTP upload will fail, move to a cleanup step to delete all data with token.

这篇关于春季批处理-整个工作的一笔交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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