Spring 集成:逐行读取文件并为每一行调用 ws
Spring integration: read file line by line and call ws for each line
我想一次从文件中检索一行,然后将该行转换为 POJO,然后检索下一行...
对于每一行,应该调用两个 Web 服务。
我相信,我应该这样工作:
<int-file:inbound-channel-adapter directory="/tmp/test"
id="filesIn" channel="toSplitter">
<int:poller fixed-delay="5000" />
</int-file:inbound-channel-adapter>
<int:splitter input-channel="toSplitter" output-channel="logger"
ref="fileSplitter" method="split" />
<int:logging-channel-adapter id="logger" level="WARN"/>
<bean id="fileSplitter" class="foo.FileSplitter" />
但是根据 sample 拆分器 return 消息列表,但我只想处理一行。我应该为此使用 spring 批处理吗?
不确定您有什么问题,但自版本 4.1.2
以来,Spring 集成提供 FileSplitter
作为开箱即用的组件。由于 4.2
它可以被指定为顶级 <int-file:splitter>
组件。
而这正是您的要求。
此外,不要忘记您可以将其中的 output-channel
指定为 ExecutorChannel
以并行处理文件中的行。
>但根据样本
根据哪个样本?
你错了,拆分器为每个拆分发出一条单独的消息。
我想一次从文件中检索一行,然后将该行转换为 POJO,然后检索下一行... 对于每一行,应该调用两个 Web 服务。
我相信,我应该这样工作:
<int-file:inbound-channel-adapter directory="/tmp/test"
id="filesIn" channel="toSplitter">
<int:poller fixed-delay="5000" />
</int-file:inbound-channel-adapter>
<int:splitter input-channel="toSplitter" output-channel="logger"
ref="fileSplitter" method="split" />
<int:logging-channel-adapter id="logger" level="WARN"/>
<bean id="fileSplitter" class="foo.FileSplitter" />
但是根据 sample 拆分器 return 消息列表,但我只想处理一行。我应该为此使用 spring 批处理吗?
不确定您有什么问题,但自版本 4.1.2
以来,Spring 集成提供 FileSplitter
作为开箱即用的组件。由于 4.2
它可以被指定为顶级 <int-file:splitter>
组件。
而这正是您的要求。
此外,不要忘记您可以将其中的 output-channel
指定为 ExecutorChannel
以并行处理文件中的行。
>但根据样本
根据哪个样本?
你错了,拆分器为每个拆分发出一条单独的消息。