简体   繁体   English

每个资源的Spring Batch MultiResourceItemReader块提交

[英]Spring Batch MultiResourceItemReader Chunk Commit Per Resource

I currently have a Spring Batch job that does the following: 我目前有一个执行以下任务的Spring Batch作业:

  1. Reads a list of csv files using a MultiResourceItemReader which delegates to a FlatFileItemReader. 使用委托给FlatFileItemReader的MultiResourceItemReader读取csv文件列表。
  2. Splits each file into chunks and writes each chunk as a JMS message, with each message containing the list of lines in the chunk and the filename of the underlying resource in JSON format. 将每个文件拆分为多个块,并将每个块作为JMS消息写入,每个消息均包含块中的行列表以及JSON格式的基础资源的文件名。

What I want is for each chunk to only contain lines from a single file resource so that the filename on the JMS message will link up to the corresponding file. 我想要的是每个块仅包含来自单个文件资源的行,以便JMS消息上的文件名将链接到相应的文件。

The problem is that when processing of one file resource is complete, the reader will just continue and process the next resource meaning that lines from multiple resource files are being inserted into the same chunk and the filename property will not necessarily match the underlying data in the chunk. 问题是,当完成一个文件资源的处理时,阅读器将继续处理下一个资源,这意味着将多个资源文件中的行插入到同一块中,并且filename属性不一定与该文件中的基础数据匹配。块。

Is there any clean way to prevent the reader from including lines from separate file resources in the same chunk? 有什么干净的方法可以防止阅读器在同一块中包含来自单独文件资源的行?

EDIT: I believe the solution will require using a custom chunk completion policy to somehow determine if the current item being read is from the same resource as the previous line, not sure how feasible this is though. 编辑:我相信解决方案将需要使用自定义块完成策略,以某种方式确定当前正在读取的项是否来自与上一行相同的资源,但不确定这样做是否可行。 Any thoughts?. 有什么想法吗?。

我将实现更改为使用MultiResourcePartitioner为每个文件创建一个分区步骤,现在一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 spring 批处理中,我们如何将处理后的文件移动到另一个文件夹,我正在使用 MultiResourceItemReader 和块处理 - In spring batch how can we move the processed files to another folder, I am using MultiResourceItemReader and chunk processing Spring 使用MultiResourceItemReader 和使用ItemReadListener 批量读取文件 - Spring batch reading files with MultiResourceItemReader and using ItemReadListener Spring批处理MultiResourceItemReader-仅用于合并文件? - Spring batch MultiResourceItemReader - only used for combining files? Spring 批处理 - 即使块引发一些异常,是否有办法提交数据? - Spring Batch - Is there a way to commit data even if the chunk raise some exception? 批量中的Spring Batch异常 - Spring Batch Exception in Chunk 春季批处理 - Spring Batch Chunk processing 在Spring Batch中解密后通过MultiResourceItemReader读取文件 - Reading Files thru MultiResourceItemReader after de-cryption in Spring Batch Spring Boot批处理-MultiResourceItemReader:错误时移至下一个文件 - Spring Boot batch - MultiResourceItemReader : move to next file on error 如何使用 spring-batch 和 MultiResourceItemReader 读取文件夹中的所有文件? - How to read all files in a folder with spring-batch and MultiResourceItemReader? Java Spring 批处理 - MultiResourceItemReader 不会在每次作业运行时读取新文件 - Java Spring Batch - MultiResourceItemReader not reading in new files every job run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM