【问题标题】:Spring Integration - File Adapter not working after first attemptSpring Integration - 第一次尝试后文件适配器不起作用
【发布时间】:2017-10-03 10:49:44
【问题描述】:

在 Spring Integration 中遇到文件适配器的一些问题,我不知道,因为我以前从未听说过。使用以下代码从 FTP 文件夹中读取文件并将其写入本地目录。

问题是服务器启动后,第一次运行正常。但是随后的调用会调用文件适配器,但文件移动过程并未发生。

Cron 计时是:0/20 * * * * ?。

对这种奇怪的行为有什么想法吗?

<int:channel id="txtFilesIn">
        <int:dispatcher task-executor="executor"/>
    </int:channel>
    <int:channel id="txtFilesOut">
        <int:dispatcher task-executor="executor"/>
    </int:channel>  

     <int-file:inbound-channel-adapter id="txtFilesIn"
        directory="${FILE_IN}"
        filename-pattern="*.csv"
         auto-startup="true">
        <int:poller cron="${CRON_TAB}" ></int:poller>
    </int-file:inbound-channel-adapter>

    <int:service-activator input-channel="txtFilesIn"
                           output-channel="txtFilesOut" 
                           ref="apiCommonService" 
                           method="readFile"/>

    <int-file:outbound-channel-adapter id="txtFilesOut"
        directory="${FILE_OUT}"
        delete-source-files="true"/>

编辑 1:

这样修改

<int-file:inbound-channel-adapter id="txtFilesIn"
        directory="${FILE_IN}"            
         auto-startup="true"
     local-filter="acceptAll">
        <int:poller cron="${CRON_TAB}" ></int:poller>
    </int-file:inbound-channel-adapter>

<bean id="acceptAll" class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />

现在工作正常。

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    &lt;int-file:inbound-channel-adapter&gt;的目标:

    FileReadingMessageSource 可用于使用来自 文件系统。这是 MessageSource 的一个实现,它创建 来自文件系统目录的消息。

    为防止为某些文件创建消息,您可以提供FileListFilter。默认使用以下 2 个过滤器:

    • IgnoreHiddenFileListFilter
    • AcceptOnceFileListFilter

    所以,它从第一次拾取文件是正确的,但如果没有任何新文件与过滤器匹配,它不会做任何后续操作。

    【讨论】:

    • 文件适配器每 10 分钟运行一次,我只是在 IN 文件夹中再次放置了一个文件。这应该有效,这就是 IIRC 存在投票的原因!但它没有发生,我不知道为什么!
    • `我刚刚又放了一个文件`。这是重要的部分(!!!)。见AcceptOnceFileListFilter。它不允许再次处理相同的文件。过滤逻辑基于文件名。因此,您必须放置具有不同名称的文件或从&lt;int-file:inbound-channel-adapter&gt; 禁用此AcceptOnceFileListFilter,据我所知,您在出站端使用delete-source-files="true"
    • 用acceptAllFilter修改了代码,效果很好。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2023-03-12
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多