JdbcPollingChannelAdapter:只手动轮询数据库
问题描述:
我有一个通过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();
}
答
好了,你去正确的方式有关JdbcPollingChannelAdapter
和commandChannel
,但是你没有配置SourcePollingChannelAdapter
你与IntegrationFlows.from(jdbcMessageSource()
做。
你需要的是真正的jdbcMessageSource()
,但轮询它手动你应该配置基于命令流:
@Bean
public IntegrationFlow jdbcFlow() {
return IntegrationFlows
.from("commandChannel")
.handle(jdbcMessageSource(), "receive")
.handle(System.out::println)
.get();
}
确切说从SourcePollingChannelAdapter
定时基础上调用。