Spring Integration Java DSL桥接器可以轮询两个不同的目录

时间:2017-12-12 22:44:07

标签: spring-integration spring-batch spring-integration-dsl

我有设置文件轮询器/通道适配器,它使用Java DSL轮询目录和处理程序集成流程。但我没有得到任何参考如何添加另一个目录/通道适配器和桥接到相同的处理程序。这是我的代码。

@Bean
public IntegrationFlow integrationFlow(JobLaunchingGateway jobLaunchingGateway) {
    return IntegrationFlows.from(Files.inboundAdapter(new File(incomingDir)).
                    filter(new SimplePatternFileListFilter("*.csv")).
                    filter(new AcceptOnceFileListFilter<>()),
            c -> c.poller(Pollers.fixedRate(500).maxMessagesPerPoll(1))).
            handle(fileMessageToJobRequest()).
            handle(jobLaunchingGateway).
            log(LoggingHandler.Level.WARN, "headers.id + ': ' + payload").
            get();
}

2 个答案:

答案 0 :(得分:1)

Spring Integration中的第一类公民之一是MessageChannel实体。您总是可以在IntegrationFlow定义中的端点之间设置显式通道,并明确地向它们发送消息。

对于“合并”用例,我建议在.channel()之前放置.handle()并为第二个目录声明第二个流,但在该流的末尾使用相同的{{ 1}}将来自此流的消息“桥接”到第一个消息的中间。

请参阅参考手册中的更多信息:https://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/java-dsl.html#java-dsl-channels

答案 1 :(得分:1)

谢谢@Artem。怎么样?

    @Bean
public IntegrationFlow integrationFlowUi(JobLaunchingGateway jobLaunchingGateway) {
    return IntegrationFlows.from(Files.inboundAdapter(new File(incomingDirUi)).
                    filter(new SimplePatternFileListFilter("*.csv")).
                    filter(new AcceptOnceFileListFilter<>()),
            c -> c.poller(Pollers.fixedRate(500).maxMessagesPerPoll(1))).
            channel("to-bridge").
            handle(fileMessageToJobRequest()).
            handle(jobLaunchingGateway).
            log(LoggingHandler.Level.WARN, "headers.id + ': ' + payload").
            get();
}

@Bean
public IntegrationFlow integrationFlowSftp(JobLaunchingGateway jobLaunchingGateway) {
    return IntegrationFlows.from(Files.inboundAdapter(new File(incomingDirSftp)).
                    filter(new SimplePatternFileListFilter("*.csv")).
                    filter(new AcceptOnceFileListFilter<>()),
            c -> c.poller(Pollers.fixedRate(500).maxMessagesPerPoll(1))).
            channel("to-bridge").get();
}