【问题标题】:Spring integration Java - how to use @InboundChannelAdapter to check a directory for files?Spring 集成 Java - 如何使用 @InboundChannelAdapter 检查目录中的文件?
【发布时间】:2015-10-27 15:25:15
【问题描述】:

如何让@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>

但是在java中?

【问题讨论】:

    标签: java spring spring-integration dsl inbound


    【解决方案1】:

    类似这样的:

    @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;
    }
    

    请另一方注意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();
        }
    

    【讨论】:

    • 感谢您的回复,它有效。另外,我已经更新了请求更多信息的问题,如果你能看看会很棒。干杯!
    • 请在单独的 SO 线程中提出该问题。它与当前的无关。
    • 当然,这里有新线程:stackoverflow.com/questions/31845269/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多