2

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?

Lukaszaq
  • 181
  • 1
  • 4
  • 16

2 Answers2

1

schedule my flow from other system

From your flow perspective it sounds like event driven action. For this purpose you should use JdbcOutboundGateway with the same SELECT.

And, of course, you should find the hook for that external system to trigger an event for your flow input channel. That might be any Inbound Channel Adapter or Message Driven Adapter, e.g. JMS, AMQP, HTTP and so. Depends what you already have in your middleware and what will be possible to expose from this your application to external systems.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Do you have any example how to use JdbcOutboundGateway as my input? – Lukaszaq Jun 02 '16 at 11:07
  • 2
    `JdbcOutboundGateway` is a `MessageHandler`, so there is just enough to configure it according its properties and refer from `.handle()` in the flow. The trigger action may done with any `IntegrationFlows.from()`. Your answer about `onlyOnceTrigger` doesn't reflect the question about "i would like to schedule my flow from other system". – Artem Bilan Jun 02 '16 at 12:11
  • When i try to use JdbcOutboundGateway i got [Assertion failed] - this argument is required; it must not be null – Lukaszaq Jun 03 '16 at 07:38
1

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();
}
Lukaszaq
  • 181
  • 1
  • 4
  • 16