2016-05-30 169 views
2

我使用spring集成從數據庫中讀取數據。 現在我使用輪詢適配器Spring集成DSL JDBC入站通道適配器

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

但我想安排從其他系統我的流程。 任何人都知道如何做到這一點?

回答

1

調度來自其它系統

我的流量從你流的角度看,它聽起來就像event driven action。爲此,您應該使用JdbcOutboundGatewaySELECT相同。

而且,當然,您應該找到該外部系統的鉤子以觸發流量輸入通道的事件。這可能是任何入站通道適配器或消息驅動適配器,例如JMS,AMQP,HTTP等。取決於您的中間件中已有的內容以及將您的應用程序暴露給外部系統的可能性。

+0

你有什麼例子,如何使用JdbcOutboundGateway作爲我的投入? – Lukaszaq

+1

'JdbcOutboundGateway'是一個'MessageHandler',所以剛好可以根據它的屬性來配置它,並從流中的'.handle()'引用。觸發器動作可以用任何'IntegrationFlows.from()'完成。你對'onlyOnceTrigger'的回答並不反映「我想從其他系統安排我的流量」的問題。 –

+0

當我嘗試使用JdbcOutboundGateway我得到[斷言失敗] - 此參數是必需的;它不能爲空 – Lukaszaq

0

我想我有一個自定義觸發解決的問題:

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(); 
} 
相關問題