将异常条款(onException)导入Camel Spring XML DSL

时间:2017-01-18 22:08:52

标签: java xml spring apache-camel

有没有办法将异常子句( onException )导入Camel Spring XML DSL,以便在 camelContext 中使用它?

它应该像 routContext 那样工作,解释为in the camel documentation。你有一个文件,其中包含 routeContext ,您可以将其导入主文件并在 camelContext 中使用它:

  

<!-- import the routes from another XML file -->
<import resource="myCoolRoutes.xml"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">

    <!-- refer to a given route to be used -->
    <routeContextRef ref="myCoolRoutes"/>

    <!-- we can of course still use routes inside camelContext -->
    <route id="inside">
        <from uri="direct:inside"/>
        <to uri="mock:inside"/>
    </route>
</camelContext>
  

所以我想要一个文件,让我们调用它myCoolException.xml,并且应该可以将它导入我的主文件。所以它会是这样的:

<import resource="myCoolException.xml"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">

    <exceptionContextRef ref="myCoolException"/>
    ...

</camelContext>

我的目标是模块化我的Camel文件,如果我想在不同的上下文中重用异常子句,不要重复自己。

1 个答案:

答案 0 :(得分:0)

我不确定我们能做到这一点。但是您可以捕获并处理异常,然后转发到常见的错误处理流程。所有骆驼语境都应该可以访问该流程。

<强>等

onException(Exception.class).handled(true).to("direct-vm:commonErrorHandler")

您可以在“direct-vm:commonErrorHandler”路由中定义常见的异常处理逻辑。您可以通过逻辑方式将多个direct-vm路由分组以在一个公共位置处理异常。