【问题标题】:Spring Integration DSL JDBC inbound channel adapterSpring Integration DSL JDBC 入站通道适配器
【发布时间】:2016-05-30 12:03:17
【问题描述】:

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

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

【问题讨论】:

    标签: java spring-integration spring-jdbc spring-dsl


    【解决方案1】:

    从其他系统安排我的流程

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

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

    【讨论】:

    • 您有任何示例如何使用 JdbcOutboundGateway 作为我的输入吗?
    • JdbcOutboundGateway 是一个MessageHandler,因此只需根据其属性配置它并在流程中从.handle() 引用即可。触发动作可以用任何IntegrationFlows.from() 来完成。您对onlyOnceTrigger 的回答并未反映有关“我想从其他系统安排我的流程”的问题。
    • 当我尝试使用 JdbcOutboundGateway 我得到 [Assertion failed] - 这个参数是必需的;它不能为空
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 2016-07-19
      • 2016-11-17
      • 2015-05-01
      相关资源
      最近更新 更多