I use spring integration to read data from database. Now i use polling adapter
@Bean
public MessageSource<Object> jdbcMessageSource() {
JdbcPollingChannelAdapter a = new JdbcPollingChannelAdapter(dataSource(), "SELECT id, clientName FROM client");
return a;
}
Flow:
@Bean
public IntegrationFlow pollingFlow() throws Exception {
return IntegrationFlows.from(jdbcMessageSource(),
c -> c.poller(Pollers.fixedRate(30000).maxMessagesPerPoll(1)))
.channel(channel1())
.handle(handler())
.get();
}
But i would like to schedule my flow from other system. Anyone know how to do this?
I think i solve the problem with a custom trigger:
public Trigger onlyOnceTrigger() {
return new Trigger() {
private final AtomicBoolean invoked = new AtomicBoolean();
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
return this.invoked.getAndSet(true) ? null : new Date();
}
};
}
And my flow:
public IntegrationFlow pollingFlow() throws Exception {
return IntegrationFlows.from(jdbcMessageSource(),
c -> c.poller(Pollers.trigger(onlyOnceTrigger()).maxMessagesPerPoll(1)))
.channel(channel1())
.handle(handler())
.get();
}