【问题标题】:Spring Integration: File Reading Splitting and Message FilteringSpring Integration:文件读取拆分和消息过滤
【发布时间】:2018-07-05 14:09:23
【问题描述】:

我正在使用 Spring Integration File Splitter (XML config) 来读取文件并处理消息。

我有一个要求,我需要从文件中读取第一行和最后一行并将它们设置为标题值,以便其余行/消息具有该信息。

换句话说,第一行和最后一行消息需要被丢弃,但其有效负载需要设置为其余消息的标头。

我怎样才能实现它?任何帮助将不胜感激。谢谢。

以下代码用于从目录中读取文件并将其拆分:

 <int-file:inbound-channel-adapter
    id="fileSource" channel="fileReceiverChannel"
    directory="file:${file.messagesource.directory}"
    prevent-duplicates="false" ignore-hidden="true" filename-regex="${filename.regex}" >
    <int:poller fixed-delay="5000" receive-timeout="5000" 
        task-executor="pollerExecutor">
    </int:poller>
</int-file:inbound-channel-adapter>

<int-file:splitter id="splitFile"
        input-channel="splitFileChannel" output-channel="transformChannel"
        charset="UTF-8" apply-sequence="true" iterator="false" />

【问题讨论】:

    标签: java spring spring-integration filereader


    【解决方案1】:

    从 5.0 开始,您可以在FileSplitter 上使用setFirstLineAsHeader(true),并且第一行将作为所有消息的标题。

    在 XML 配置中是 first-line-as-header

    没有机制可以对“最后”行执行相同的操作;你需要一个自定义版本的分离器。读取最后一行并不容易,除非所有行的长度相同,否则您必须先读取整个文件。

    【讨论】:

    • 感谢@Gary Russell 的快速回复。
    • 一个简单的问题:我可以使用 只获取最后一行吗?它可以在 windows 和 linux 上运行吗?还是我需要编写一个扩展 ApacheCommonsFileTailingMessageProducer 的类?谢谢。
    猜你喜欢
    • 1970-01-01
    • 2016-01-19
    • 2023-04-09
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2014-07-03
    相关资源
    最近更新 更多