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

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

问题描述

我正在使用 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.

因此,我有两个步骤:一个从 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.

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

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