Spring Splitter output to multiple channels

1.7k Views Asked by At

I am using the splitter to split the messages and to pass it to the respective other channels for further processing.

But I wanted to send the splitter output to one channel which will write it into another file. Also wanted to send the splitter output to another channel which will perform some task.

I am able to do the same by using the below, but it doesn't seems to be working if failed to process any of the split record in channel2. Its stopping the process and not writing the remaining records in 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>

Is there any other way I can pass it to the separate channels independently.

1

There are 1 best solutions below

3
On BEST ANSWER

The recipient-list-router has an option like:

/**
 * 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) {

Or if you wish for XML configuration:

<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>