gpt4 book ai didi

spring-batch - Spring Batch - 跳过过程记录

转载 作者:行者123 更新时间:2023-12-04 17:34:12 29 4
gpt4 key购买 nike

我想跳过一些过程记录。

我尝试过的是,我创建了自定义异常并在我想跳过记录时抛出异常,并且它调用了 onSkipInProcess 方法的跳过监听器。它工作正常。

请找到配置。

 <batch:chunk reader="masterFileItemReader" writer="masterFileWriter" processor="itemProcessor" commit-interval="5000" skip-limit="100000" >
<batch:skippable-exception-classes>
<batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
<batch:include class="com.exception.SkipException"/>
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="recordSkipListener"/>
</batch:listeners>

但我想知道有没有其他方法可以跳过过程记录?

问候,
香卡

最佳答案

确实有两种方法可以做到这一点,一种是你提到的跳过机制,另一种是返回 null这将过滤掉项目而不是写出来。这是documentation link - 6.3.2. Filtering records在那里很好地解释了两种方法之间的区别。还有这个 blog post解释跳过细节和批量交易。

当您即解析 csv 文件并且您期望每行 5 个项目但一行包含 6 个无效项目时,您可以选择跳过它(通过将阅读器异常标记为可跳过并在策略中定义条件,如您所举的例子)。但是,如果每一行都包含名称并且您的用例是不写以字母 N 开头的项目返回 null 可以更好地实现(过滤项目),因为它是有效的项目,但不符合您的业务案例。

另请注意,如果您返回 null这些项目的数量将在 StepContextgetFilterCount()如果您使用跳过方法,它们将位于 getReadSkipCount() , getProcessorSkipCountgetWriteSkipCount尊敬。

关于spring-batch - Spring Batch - 跳过过程记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29031155/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com