1

我有一个骆驼蓝图定义,其中有两个骆驼上下文,每个上下文都包含一条路线。

调用第一个上下文路由,然后调用第二个上下文的路由。现在,如果在第二条路线中抛出 Exception 并且onException设置handled=true,则在第一条路线doFinally块中,仅调用第一个处理器。

这是我的蓝图定义:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:camel="http://camel.apache.org/schema/blueprint"
          xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
      http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="myException" class="java.lang.RuntimeException">
        <argument value="Booom" />
    </bean>

    <camelContext id="firstContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="firstRoute">
            <from uri="direct-vm:start"/>
            <doTry>
                <to uri="log:FIRST_TRY"/>
                <to uri="direct-vm:generateException"/>
                <to uri="log:SECOND_TRY"/>
                <doFinally>
                    <to uri="log:FIRST_FINALLY"/>
                    <to uri="log:SECOND_FINALLY"/>
                </doFinally>
            </doTry>
            <log message="The message contains ${body}"/>
            <to uri="mock:result"/>
        </route>
    </camelContext>

    <camelContext id="secondContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <onException>
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>
        </onException>
        <route id="secondRoute">
            <from uri="direct-vm:generateException"/>
            <throwException ref="myException"/>
        </route>
    </camelContext>

</blueprint>

只有<to uri="log:FIRST_FINALLY"/>被打印出来。我看不到<to uri="log:SECOND_FINALLY"/>. 我在这里错过了什么吗?任何帮助表示赞赏。

我在 Apache Servicemix 4.5.2 中使用 Camel 2.10.6。

问候多米尼克

4

1 回答 1

0

您可以考虑使用多播 [1] 作为解决此问题的方法。

<doFinally>
  <multicast>
    <to uri="log:FIRST_FINALLY"/>
    <to uri="log:SECOND_FINALLY"/>
  </multicast>
</doFinally>

这当然与流水线处理不同,但在某些情况下,doFinallyblock 可以独立发送两条消息。

[1] http://camel.apache.org/multicast

于 2014-01-14T13:22:41.477 回答