Spring集成Java - 如何使用@InboundChannelAdapter检查目录中的文件?

Oce*_*lot 5 java dsl spring inbound spring-integration

如何让@InboundChannelAdapter处理文件?这样的事情:

<int-file:inbound-channel-adapter id="executionMessageFileInputChannel"
                                      directory="file:${fpml.messages.input}"
                                      prevent-duplicates="false" filename-pattern="*.xml">
        <int:poller fixed-delay="20000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>
Run Code Online (Sandbox Code Playgroud)

但在java?

Art*_*lan 7

像这样的东西:

@Bean
@InboundChannelAdapter(value = "executionMessageFileInputChannel",
        poller = @Poller(fixedDelay = "20000", maxMessagesPerPoll = "1"))
public MessageSource<File> fileMessageSource(@Value("${fpml.messages.input}") File directory) {
    FileReadingMessageSource fileReadingMessageSource = new FileReadingMessageSource();
    fileReadingMessageSource.setDirectory(directory);
    fileReadingMessageSource.setFilter(new SimplePatternFileListFilter("*.xml"));
    return fileReadingMessageSource;
}
Run Code Online (Sandbox Code Playgroud)

从另一方面请注意Spring Integration Java DSL项目,使用它可能看起来像:

    @Bean
    public IntegrationFlow fileReadingFlow(@Value("${fpml.messages.input}") File directory) {
        return IntegrationFlows
                .from(s -> s.file(directory).patternFilter("*.xml"),
                        e -> e.poller(Pollers.fixedDelay(20000)))
        .....................
                .get();
    }
Run Code Online (Sandbox Code Playgroud)