2017-05-25 40 views
1

我正在使用分離器來拆分消息並將其傳遞到相應的其他通道進行進一步處理。彈簧分離器輸出到多個通道

但我想將分離器輸出發送到一個通道,將其寫入另一個文件。還希望將分離器輸出發送到將執行一些任務的另一個通道。

我可以通過使用下面的方法來做同樣的事情,但是如果無法處理channel2中的任何分割記錄,似乎不能工作。它停止進程並且不寫入channel1中的剩餘記錄。

<int:splitter input-channel="inputchannel" ref="splitter" method="doSplit" output-channel="routingChannel"/> 

    <int-recipient-list-router id="customRouter" input-channel="routingChannel" 
     <int:recipient channel="channel1"/> <!--Write to file--> 
     <int:recipient channel="channel2"/> <!-- logic to process --> 
    </int:reciepient-list-router> 

是否有任何其他方式我可以將它傳遞到單獨的獨立通道。

回答

1

recipient-list-router有類似的選項:

/** 
* Specify whether send failures for one or more of the recipients should be ignored. By default this is 
* <code>false</code> meaning that an Exception will be thrown whenever a send fails. To override this and suppress 
* Exceptions, set the value to <code>true</code>. 
* @param ignoreSendFailures true to ignore send failures. 
*/ 
public void setIgnoreSendFailures(boolean ignoreSendFailures) { 

或者,如果你希望XML配置:

<xsd:attribute name="ignore-send-failures"> 
     <xsd:annotation> 
      <xsd:documentation><![CDATA[ 
       If set to "true", failures to send to a message channel will 
       be ignored. If set to "false", a MessageDeliveryException will be 
       thrown instead, and if the router resolves more than one channel, 
       any subsequent channels will not receive the message. 

       Please be aware that when using direct channels (single threaded), 
       send-failures can be caused by exceptions thrown by components 
       much further down-stream. 

       This attribute defaults to false. 
      ]]></xsd:documentation> 
     </xsd:annotation> 
     <xsd:simpleType> 
      <xsd:union memberTypes="xsd:boolean xsd:string" /> 
     </xsd:simpleType> 
    </xsd:attribute> 
+0

阿爾喬姆感謝您的答覆。如果我們添加忽略發送失敗,但是channel1正在完成,雖然在channel2中發生了任何異常。但是然後控制不會進入錯誤通道.. :( – kattoor

+0

好的。您可以將''channel放置在'splitter'和'router',然後在路由器的''上加上'error-channel',但是應該關掉ignore-send-failure。這樣,通過隊列,你可以從異常中釋放splitter線程,繼續發出 –

+0

非常感謝Artem。我試着用下面的任務執行器,它工作:)希望做同樣的工作? ' – kattoor