Reputation: 3152
I have a JdbcPollingChannelAdapter which reads data via JDBC. I want to make it poll manually (using a commandChannel). It should never poll automatically, and it should run immediately when I trigger a manual poll.
Below I am using a poller which runs every 24 hours to get the channel running at all. I cannot use a cronExpression that never fires as in Quartz: Cron expression that will never execute since Pollers.cronExpression() takes no year.
@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();
}
Upvotes: 2
Views: 702
Reputation: 121560
Well, you go right way about JdbcPollingChannelAdapter
and commandChannel
, but you don't have configure SourcePollingChannelAdapter
as you do with that IntegrationFlows.from(jdbcMessageSource()
.
What you need is really the jdbcMessageSource()
, but to poll it manually you should configure command-based flow:
@Bean
public IntegrationFlow jdbcFlow() {
return IntegrationFlows
.from("commandChannel")
.handle(jdbcMessageSource(), "receive")
.handle(System.out::println)
.get();
}
Exactly that receive()
is called from the SourcePollingChannelAdapter
on the timing basis.
Upvotes: 2