【问题标题】:how to prevent process on old files in `int-ftp:inbound-channel-adapter `?如何防止处理`int-ftp:inbound-channel-adapter`中的旧文件?
【发布时间】:2016-05-24 10:47:33
【问题描述】:

感谢关注
我在spring集成中使用int-ftp:inbound-channel-adapter,我想从ftp服务器检索文件并在其上处理,并将备份保存在本地目录中,但是当应用程序处于启动状态int-ftp:inbound-channel-adapter从备份位置的本地旧文件创建消息并尝试发送如下引导我的代码:

 <bean id="acceptOnceFilter"
          class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />

     <int-ftp:inbound-channel-adapter id="sam-inbound-channel-adapter"
                                         channel="sam-ready-to-process-inbound"
                                         session-factory="sam-ftp-Session"
                                         auto-create-local-directory="true"
                                         delete-remote-files="true"
                                         auto-startup="true"
                                         filename-pattern="*.bmp"
                                         remote-directory="/in/"
                                         remote-file-separator="/"
                                         local-filter="acceptOnceFilter"
                                         preserve-timestamp="true"
                                         local-filename-generator-expression="@fileName.name('sam',#this)"
                                         temporary-file-suffix=".writing"
                                         local-directory="./backup/sam/in//">
            <int:poller fixed-rate="10000"/>
        </int-ftp:inbound-channel-adapter>

提前致谢

【问题讨论】:

    标签: java spring-boot spring-integration spring-batch


    【解决方案1】:

    see the documentation。您可以在local-filter 中使用FileSystemPersistentAcceptOnceFileListFilter 以及您选择的MetadataStore,以防止文件在重新启动后被重新处理。

    但是,通常最好在处理后删除/重命名文件;否则,随着本地目录中需要扫描的文件数量的增加,性能会随着时间的推移而下降。

    由于您要删除远程文件,因此不需要它,但是(为了完整性)还有一个FtpPersistentAcceptOnceFileListFilter(在filter中)以防止重新启动后重新获取文件(@987654327时需要@ 是假的)。

    【讨论】:

    • 感谢@Gary 的回复,是的,您是对的,我使用了tmp 目录并将文件移动到另一个目录进行处理并解决了我的问题。
    【解决方案2】:

    感谢@Gary 帮助我设计我的项目,为了解决我使用int-file:outbound-gateway 将文件移动到另一个目录的问题,如下所示:

    <int:channel id="ready-to-process-inbound"/>
    <int:channel id="ready-to-process-inbound-tmp-mover"/>
    
      <int-ftp:inbound-channel-adapter id="inbound-channel-adapter"
                                         channel="ready-to-process-inbound-tmp-mover"
                                         session-factory="ftp-Session"
                                         auto-create-local-directory="true"
                                         delete-remote-files="true"
                                         auto-startup="true"
                                         filename-pattern="*.bmp"
                                         remote-directory="/in/"
                                         remote-file-separator="/"
                                         preserve-timestamp="true"
                                         local-filename-generator-expression="@fileNameGenerator.by('prefix',#this)"
                                         temporary-file-suffix=".writing"
                                         local-directory="./backup//tmp//">
            <int:poller fixed-rate="10000"/>
        </int-ftp:inbound-channel-adapter>
    
     <int-file:outbound-gateway id="file-outbound-gateway-tmp-mover"
                                   request-channel="ready-to-process-inbound-tmp-mover"
                                   reply-channel="ready-to-process-inbound"
                                   directory="./backup//in//"
                                   mode="REPLACE" delete-source-files="true"/>
    

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      相关资源
      最近更新 更多