【问题标题】:Spring Splitter output to multiple channelsSpring Splitter 输出到多个通道
【发布时间】:2017-05-26 01:45:44
【问题描述】:

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

但我想将拆分器输出发送到一个通道,该通道会将其写入另一个文件。还想将分离器输出发送到另一个执行某些任务的通道。

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

有没有其他方法可以独立地将它传递到单独的通道。

【问题讨论】:

    标签: spring spring-integration splitter message-channel


    【解决方案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>
    

    【讨论】:

    • 感谢 Artem 的回复。如果我们添加ignore-send-failures,尽管channel2中发生任何异常,但channel1正在完成。但是控制不会出错通道.. :(
    • 好的。您可以将&lt;queue&gt; 频道放在splitterrouter 之间。并将error-channel 添加到路由器的&lt;polled&gt;。但随后ignore-send-failure 应该被关闭。这样,通过队列,您可以从异常中释放拆分线程,它将继续发出
    • 非常感谢 Artem。我尝试了如下的任务执行器,它起作用了:) 希望 做同样的工作? &lt;int:channel id="routingChannel"&gt; &lt;int:dispatcher task-executor="exec" /&gt; &lt;/int:channel&gt; &lt;task:executor id="exec" pool-size="10" /&gt;
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 2020-03-04
    • 2012-01-11
    • 2011-06-25
    • 2016-05-28
    • 1970-01-01
    • 2022-01-17
    • 2016-02-13
    相关资源
    最近更新 更多