Выход Spring Splitter на несколько каналов
Я использую сплиттер для разделения сообщений и передачи их на соответствующие другие каналы для дальнейшей обработки.
Но я хотел отправить вывод сплиттера на один канал, который запишет его в другой файл. Также хотел отправить вывод сплиттера на другой канал, который будет выполнять какую-то задачу.
Я могу сделать то же самое, используя приведенное ниже, но, похоже, он не работает, если не удалось обработать какую-либо разделенную запись в канале 2. Это останавливает процесс и не записывает оставшиеся записи в 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>