2017-05-26 109 views
2

的服務激活併發單元我有一個非常簡單的Spring集成管道安裝Spring集成 - JPA入站通道適配器,分路器,工作

  1. 負荷N次資產有狀態X,與JPA,進入通道
  2. 將每個JPA實體到一個新的信道
  3. 進程JPA實體,使用服務活化劑,最後更新該實體的狀態至Y

此PIP的同步性質eline意味着JPA入站通道適配器只有在先前入站通道適配器中的所有消息被處理後纔會觸發,然後發送到分割通道併發送到nullChannel

這很有效,但效率很低。

服務激活器會執行一些操作,其中之一是它調用外部REST API,然後更新資產的狀態,因此它將從#1中排除。

這裏的問題是服務激活器需要大約1秒來處理單個消息(這時大部分時間是對REST API的調用),因此,250個JPA實體的隊列可能需要250秒處理。

如果我們同時調用REST API,說5次,它仍然需要1秒。因此,我想知道是否可以對我們的管道進行簡單的更改,可能會添加AggregatorTask Executor,這將允許整個管道作爲同步的「工作單元」運行,但允許Service Activator同時處理。

這是整合配置

<channel id="newAssetChannel" /> 
<channel id="splitAssetChannel" /> 

<int-jpa:inbound-channel-adapter 
     id="newAssetChannelAdapter" 
     channel="newAssetChannel" 
     entity-manager-factory="entityManagerFactory" 
     entity-class="com.foo.domain.Asset" 
     jpa-query="select a from Asset a where (a.status = 'NEW' or a.status = 'UPDATED') and a.health = 'OK' ORDER BY a.priority DESC, a.updatedDate ASC" 
     max-results="250"> 
    <poller fixed-rate="5000" max-messages-per-poll="1" /> 
</int-jpa:inbound-channel-adapter> 

<splitter expression="payload" 
    input-channel="newAssetChannel" 
    output-channel="splitNewAssetChannel" /> 

<service-activator 
    id="newAssetServiceActivator" 
    input-channel="splitNewAssetChannel" 
    output-channel="nullChannel" 
    ref="assetProcessor" 
    method="processNew" /> 

回答

1

那麼,aggregator真的去等待所有答覆的正確途徑,但與你自由輪詢的手ExecutorChannelsplitter一起反正。所以,在平行分裂 - 聚合之前,你應該有一些障礙。

你可以做到這一點與<gateway>

<gateway id="gateway" default-request-channel="splitterChannel"/> 

<service-activator id="gatewayTestService" input-channel="newAssetChannel" output-channel="saveRowsChannel" ref="gateway"/> 

分離器的output-channel必須ExecutorChannelnewAssetServiceActivator必須輸出到aggregator。聚合器沒有output-channel表示對該gateway的回覆。

+0

這讓我走上了正確的道路,並且一定會讓我更好地理解Spring Integration。完整更新的配置在這裏(評論贊賞的要點,如果我已經做了一些可以改進) - gist.github.com/shainegordon/66da307b2e89f69e549b675ffbfd363 e – kabal

相關問題