Spring Splitter输出到多个通道

时间:2017-05-25 17:40:29

标签: spring spring-integration splitter message-channel

我正在使用拆分器拆分消息并将其传递到相应的其他通道以进行进一步处理。

但是我想将分离器输出发送到一个通道,将其写入另一个文件。还希望将分离器输出发送到另一个执行某项任务的通道。

我可以通过使用下面的方法来做同样的事情,但是如果无法处理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 个答案:

答案 0 :(得分: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>