2

我使用 spring 集成从数据库中读取数据。现在我使用轮询适配器

@Bean
public MessageSource<Object> jdbcMessageSource() {
   JdbcPollingChannelAdapter a = new JdbcPollingChannelAdapter(dataSource(), "SELECT id, clientName FROM client");
   return a;
}

流动:

@Bean
public IntegrationFlow pollingFlow() throws Exception {
    return IntegrationFlows.from(jdbcMessageSource(), 
                c -> c.poller(Pollers.fixedRate(30000).maxMessagesPerPoll(1)))
            .channel(channel1())
            .handle(handler())
            .get();
}

但我想从其他系统安排我的流程。有人知道怎么做吗?

4

2 回答 2

1

从其他系统安排我的流程

从您的流程角度来看,这听起来像event driven action。为此,您应该使用JdbcOutboundGateway相同的SELECT.

而且,当然,您应该找到该外部系统的挂钩来触发流输入通道的事件。这可能是任何入站通道适配器或消息驱动适配器,例如 JMS、AMQP、HTTP 等。取决于您在中间件中已有的内容,以及您的应用程序可以将哪些内容暴露给外部系统。

于 2016-05-31T21:16:32.507 回答
1

我想我用自定义触发器解决了这个问题:

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();
              }
       };
}

我的流程:

public IntegrationFlow pollingFlow() throws Exception {
    return IntegrationFlows.from(jdbcMessageSource(), 
                c -> c.poller(Pollers.trigger(onlyOnceTrigger()).maxMessagesPerPoll(1)))
            .channel(channel1())
            .handle(handler())
            .get();
}
于 2016-06-01T13:44:07.883 回答