【问题标题】:Import Exception Clause (onException) into Camel Spring XML DSL将异常子句 (onException) 导入 Camel Spring XML DSL
【发布时间】:2017-06-03 11:25:21
【问题描述】:

有没有办法将异常子句 (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 文件,如果我想在不同的上下文中重用异常子句,请不要重复自己。

【问题讨论】:

    标签: java xml spring apache-camel


    【解决方案1】:

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

    喜欢,

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

    您可以在“direct-vm:commonErrorHandler”路由中定义通用异常处理逻辑。同样的方式,您可以将多个直接虚拟机路由进行逻辑分组,以便在一个共同的地方处理您的异常。

    【讨论】:

    • 嘿@Gnana Guru,谢谢你的建议。对我来说这似乎是个好主意,所以我会尝试给你反馈。
    猜你喜欢
    • 1970-01-01
    • 2015-03-29
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多