【问题标题】:Spring Integration: The file is read twice from the folderSpring Integration:从文件夹中读取文件两次
【发布时间】:2017-08-11 13:09:53
【问题描述】:

我有以下 Spring Integration 配置:

<int-file:inbound-channel-adapter
            auto-startup="true"
            channel="localInboundFilesChannel"
            directory="${in.received}"
            auto-create-directory="true">
        <int:poller fixed-rate="60" time-unit="SECONDS"/>
    </int-file:inbound-channel-adapter>

<int-file:outbound-gateway
        auto-startup="true"
        request-channel="localInboundFilesChannel"
        reply-channel="localProcessingFilesChannel"
        directory="${in.processed}"
        auto-create-directory="true"
        delete-source-files="true"
        requires-reply="false"
/>

轮询器每 1 分钟运行一次,将文件从一个文件夹复制到另一个文件夹并执行其他操作(我不提供后续步骤的代码)。

但是当我将一些文件放入目录时,我看到它被读取了两次,所以在日志中看到:

2017-08-11 14:06:31,250  INFO  org.springframework.integration.file.FileReadingMessageSource - Created message: [GenericMessage [payload=target\received\request.csv, headers={id=1f4d1ac0-823e-f3b0-2554-caae8e330682, timestamp=1502453191250}]]
2017-08-11 14:06:31,250  INFO  org.springframework.integration.file.FileReadingMessageSource - Created message: [GenericMessage [payload=target\received\request.csv, headers={id=73076423-f1ba-7cbe-a4c2-c5f02220e3f5, timestamp=1502453191250}]] 

我应该如何解决它? Spring Integrations bean 配置有什么问题吗?

【问题讨论】:

  • 是每分钟发生一次还是每分钟发生一次?
  • 也许您以某种方式加载了应用程序上下文的 2 个副本?
  • 我们有没有机会在我们身边玩一个简单的应用程序?您现在显示的是该组件的标准行为。开箱即用地有这样一个意想不到的状态真的很糟糕......
  • 是的,应用程序上下文的 2 个副本已加载,这是问题的原因。谢谢

标签: spring spring-integration


【解决方案1】:

当你声明 bean FileReadingMessageSource 时,添加一个过滤器 org.springframework.integration.file.filters.AcceptOnceFileListFilter。更多信息请参考IntegrationFlows with FileReadingMessageSource triggering job twice for same input file

【讨论】:

    猜你喜欢
    • 2015-03-26
    • 2014-11-14
    • 1970-01-01
    • 2017-11-08
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2011-10-11
    相关资源
    最近更新 更多