本文介绍了使用 Spring Integration 同时读取 CSV 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 spring 集成同时处理 CSV 文件.每一行都将转换为单独的消息.所以假设我在 CSV 文件中有 10K 行,我想启动 10 个线程,每一行都将传递给这个线程.如果有人向我展示任何示例示例,那就太好了.

I would like to process CSV file concurrently using spring integration. Each row will be converted into individual message. So Assuming I am having 10K rows in CSV file , I would like to start 10 Thread , each row will be pass to this Thread. it would be great if anyone show me any sample example.

谢谢

推荐答案

Spring Integration 4.0 支持 Iterator 作为 payload 拆分.因此,您可以将入站 File 转换为 LineIterator 并并行处理每一行的消息,如果 output-channelsplitter>ExecutorChannel:

Starting with Spring Integration 4.0 the <splitter> supports Iterator as payload to split. Hence you can convert inbound File to the LineIterator and process messages for each line in paralle, if an output-channel of <splitter> is ExecutorChannel:

<splitter input-channel="splitChannel" output-channel="executorChannel"
          expression="T(org.apache.commons.io.FileUtils).lineIterator(payload)"/>

这篇关于使用 Spring Integration 同时读取 CSV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:58