2016-06-16 46 views
0

我在Spring集成中遇到了一些基本問題。我嘗試在其他線程中搜索,但對答案不滿意。所以這是我的問題。任何提示將不勝感激。

我想從4個不同的來源並行獲取數據並聚合數據。

我的理解(根據我之前閱讀的其中一個線程),分離器的任何輸出通道如果是直接通道,則請求將按順序路由。

但是Splitter的輸出通道是一個接收者列表路由器。當我調試請求被順序路由。所以經過一些分析,我發現我們可以使用有效載荷類型的路由器並行處理。

因此,我將路由器更改爲有效載荷類型的路由器,並且請求仍按順序路由。

所以我改變了我的策略,並使用發佈訂戶頻道,並將所有訂閱頻道的輸出連接到聚合器,以便我可以彙總結果。我能夠並行採集數據,但我沒有看到響應被路由到聚合。我做錯了嗎?請建議!

Spring集成聚合器與發佈訂閱者相結合

<int:publish-subscribe-channel id="PublishSubscriberChannel" 
    task-executor="taskExecutor" /> 

<task:executor id="taskExecutor" pool-size="5" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource1" output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource2" output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="getVehicleInfoWithAdditionalAttributes" 
    output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource4" output-channel="lookupAggregatorChannel" /> 

回答

0

所以最後我發現我做錯了。最初,我正在研究Spring Integration Version 2.0。這是一箇舊的應用程序。所以,當我的代碼完全是問題中給出的內容時,我看不到將請求路由到Aggregator。 然後,當我將Spring版本升級到4.3.2 RELEASE時,我開始發現相關策略可能爲空的錯誤。那是當我發現聚合器需要一個相關ID,並且如果我有分離器相關ID自動添加和發佈 - 訂閱頻道,我們需要添加apply-sequence =「true」,以添加一個默認的相關ID,它可以由聚合器使用。所以從本質上講,這就是我的代碼現在的樣子,完全可以正常工作。

<int:publish-subscribe-channel id="PublishSubscriberChannel" apply-sequence="true" 
    task-executor="taskExecutor" /> 

<task:executor id="taskExecutor" pool-size="5" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource1" output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource2" output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource3" 
    output-channel="lookupAggregatorChannel" /> 

<int:service-activator input-channel="PublishSubscriberChannel" 
    ref="lookUpService" method="lookupSource4" output-channel="lookupAggregatorChannel" />