2017-04-27 27 views
1

我有一個通過JDBC讀取數據的JdbcPollingChannelAdapter。我想讓它手動輪詢(使用commandChannel)。它不應該自動輪詢,並且它應該在我觸發手動輪詢時立即運行。JdbcPollingChannelAdapter:隻手動輪詢數據庫

下面我使用了一個輪詢器,它每24小時運行一次以獲得運行的頻道。因爲Pollers.cronExpression()不需要年份,所以我不能使用不會像Quartz: Cron expression that will never execute那樣激發的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(); 
} 

回答

1

好了,你去正確的方式有關JdbcPollingChannelAdaptercommandChannel,但是你沒有配置SourcePollingChannelAdapter你與IntegrationFlows.from(jdbcMessageSource()做。

你需要的是真正的jdbcMessageSource(),但輪詢它手動你應該配置基於命令流:

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

確切說從SourcePollingChannelAdapter定時基礎上調用。