2017-05-11 41 views
0

我試圖設計一個消息處理管道,需要使用多個端點處理消息。在每個階段,端點都會返回有效負載(可能會被轉換)或錯誤消息。下面是我在我的腦海一般示例:彈簧集成 - 處理流水線 - 設計

<int:payload-type-router input-channel="preprocessing-output"> 
     <int:mapping type="com.example.Error" channel="error" /> 
     <int:mapping type="com.example.PreprocessedDomainObject" channel="validation-input"/> 
</int:payload-type-router> 

<int:service-activator input-channel="validation-input" 
     ref="validationService" method="validate" output-channel="validation-output"/> 

<int:payload-type-router input-channel="validation-output"> 
      <int:mapping type="com.example.Error" channel="error" /> 
      <int:mapping type="com.example.CouldBeAnotherObject" channel="processor-input"/> 
</int:payload-type-router> 

等等,這個處理鏈可能會很長...有沒有更好的方式來設計這個,而不是每一個階段之後的有效載荷類型的路由器?有點覺得多餘。

回答

0

那麼,我會根據例外情況制定。驗證服務應該拋出異常,並且您需要的只是將其發送給調用方,或者如果它是入站通道適配器,則需要使用errorChannel

這樣你就不需要那些路由器定義,只需簡單的服務調用鏈。