【问题标题】:Spring Integration - FileSystemPersistentAcceptOnceFileListFilter filtering files with same name but different timestampSpring Integration - FileSystemPersistentAcceptOnceFileListFilter 过滤具有相同名称但不同时间戳的文件
【发布时间】:2017-03-08 22:22:39
【问题描述】:

我有一个 Spring 集成应用程序,一旦文件存在于本地目录中,它就会对文件进行一些处理。处理完文件后,它会将文件移动到已处理的目录中。

一段时间后,一个新文件出现在同一个本地目录中,文件名相同,但内容和时间戳不同。应用程序应再次处理该文件,然后将其移动到已处理的目录中……但永远不会生成消息。这是配置:

@Bean
@InboundChannelAdapter(value = "dailyFileInputChannel", poller = @Poller(maxMessagesPerPoll = "1", fixedDelay = "${load.manualPollingInterval}"))
public MessageSource<File> messageSource(ApplicationProperties applicationProperties) {
    FileReadingMessageSource source = new FileReadingMessageSource();
         
    source.setDirectory(applicationProperties.getLoadDirectory());
    CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<File>();
    compositeFileListFilter.addFilter(new LastModifiedFileListFilter());
    FileSystemPersistentAcceptOnceFileListFilter persistent = new FileSystemPersistentAcceptOnceFileListFilter(store(), "dailyfilesystem");
    persistent.setFlushOnUpdate(true);
    compositeFileListFilter.addFilter(persistent);
    compositeFileListFilter.addFilter(new SimplePatternFileListFilter(applicationProperties.getFileNamePattern()));
    source.setFilter(compositeFileListFilter);
    return source;
}

@Bean
public PropertiesPersistingMetadataStore store() {
    PropertiesPersistingMetadataStore store = new PropertiesPersistingMetadataStore();
    store.setBaseDirectory(applicationProperties.getProcessedStoreDirectory());
    store.setFileName(applicationProperties.getProcessedStoreFile());
    return store;
}

@Bean
@ServiceActivator(inputChannel = "dailyFileInputChannel")
public MessageHandler handler() {
    // return a handler that processes and moves the file
}

我不希望应用程序处理具有相同名称和相同修改时间戳的文件。如何确保应用程序仍然处理具有相同名称但不同时间戳的文件?

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    使用ChainFileListFilter 而不是CompositeFileListFilter

    后者将所有文件呈现给每个过滤器,因此,如果 LastModifiedFileListFilter 在第一次尝试时过滤文件(并且 FileSystemPersistentAcceptOnceFileListFilter 通过它),则复合过滤器会过滤文件;在下一次尝试时,它将再次被过滤,即使它通过了第一个过滤器。

    ChainFileListFilter 不会将由LastModifiedFileListFilter 过滤的文件传递给下一个过滤器。

    这是最近的“修复”(在 4.3.7 JIRA here 中)。

    当前版本是 4.3.8。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2022-10-17
      • 2021-11-15
      相关资源
      最近更新 更多