【问题标题】:JdbcPollingChannelAdapter: Poll database manually onlyJdbcPollingChannelAdapter:仅手动轮询数据库
【发布时间】:2017-04-27 09:53:00
【问题描述】:

我有一个通过 JDBC 读取数据的 JdbcPollingChannelAdapter。我想手动进行轮询(使用 commandChannel)。它永远不应该自动轮询,它应该在我触发手动轮询时立即运行。

下面我使用了一个轮询器,它每 24 小时运行一次,以使频道完全运行。我不能使用像Quartz: Cron expression that will never execute 那样从不触发的 cronExpression,因为 Pollers.cronExpression() 不需要一年。

@Bean
public MessageSource<Object> jdbcMessageSource() {
    return new JdbcPollingChannelAdapter(this.dataSource, "SELECT...");
}

@Bean
public IntegrationFlow jdbcFlow() {
    return IntegrationFlows
            .from(jdbcMessageSource(),
                    spec -> spec.poller(
                        Pollers.fixedRate(24, TimeUnit.HOURS)))
            .handle(System.out::println)
            .get();
}

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    好吧,您对JdbcPollingChannelAdaptercommandChannel 进行了正确的配置,但是您没有像使用IntegrationFlows.from(jdbcMessageSource() 那样配置SourcePollingChannelAdapter

    您真正需要的是jdbcMessageSource(),但要手动轮询它,您应该配置基于命令的流程:

    @Bean
    public IntegrationFlow jdbcFlow() {
        return IntegrationFlows
                .from("commandChannel")
                .handle(jdbcMessageSource(), "receive")
                .handle(System.out::println)
                .get();
    }
    

    receive() 正是在时间基础上从SourcePollingChannelAdapter 调用的。

    【讨论】:

      猜你喜欢
      • 2015-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      相关资源
      最近更新 更多