gpt4 book ai didi

java - 将异常子句 (onException) 导入 Camel Spring XML DSL

转载 作者:行者123 更新时间:2023-12-01 09:00:18 33 4
gpt4 key购买 nike

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

最佳答案

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

喜欢,

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

您可以在“direct-vm:commonErrorHandler”路由中定义通用异常处理逻辑。您可以以同样的方式对多个 direct-vm 路由进行逻辑分组,以在一个公共(public)位置处理异常。

关于java - 将异常子句 (onException) 导入 Camel Spring XML DSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41730336/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com