Выход Spring Splitter на несколько каналов

Я использую сплиттер, чтобы разделить сообщения и передать их соответствующим другим каналам для дальнейшей обработки.

Но я хотел отправить вывод сплиттера на один канал, который запишет его в другой файл. Также хотел направить вывод сплиттера на другой канал, который будет выполнять какую-то задачу.

Я могу сделать то же самое, используя приведенное ниже, но, похоже, это не работает, если не удалось обработать какую-либо разделенную запись в канале 2. Он останавливает процесс и не записывает оставшиеся записи в канал 1.

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

Есть ли другой способ, которым я могу передать его на отдельные каналы самостоятельно.


person kattoor    schedule 25.05.2017    source источник


Ответы (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>
person Artem Bilan    schedule 25.05.2017
comment
Спасибо Артем за ответ. Канал 1 завершается, хотя в канале 2 возникло какое-либо исключение, если мы добавим ignore-send-failures. Но тогда управление не переходит на канал ошибок.. :( - person kattoor; 26.05.2017
comment
В порядке. Вы можете поместить <queue> канал между splitter и router. И добавьте error-channel к <polled> роутера. Но тогда ignore-send-failure надо отключить. Таким образом, через очередь вы освобождаете поток сплиттера от исключений, и он будет продолжать испускать - person Artem Bilan; 26.05.2017
comment
Спасибо большое Артем. Я попробовал с исполнителем задач, как показано ниже, и это сработало :) Надеюсь, «очередь» и «исполнитель задач» выполняют одну и ту же работу? <int:channel id="routingChannel"> <int:dispatcher task-executor="exec" /> </int:channel> <task:executor id="exec" pool-size="10" /> - person kattoor; 26.05.2017
comment
Ну, почти. Прочтите о QueueChannel и ExecutorChannel в Справочном руководстве. Между тем, если ответ вас устраивает, подумайте об этом: stackoverflow.com/help/someone-answers - person Artem Bilan; 26.05.2017