防止驼峰初始化端点

时间:2017-05-05 14:35:50

标签: apache-camel

我在路由中有一个无法在本地实例化的端点 - 由于某些缺少的属性不可用且无法在本地环境中访问。

因此,当我在本地环境中启动应用程序时,我收到错误org.apache.camel.FailedToCreateRouteException。但是在服务器环境中它可以正常工作。

如何防止驼峰在本地环境中初始化端点(我有一个属性可以找出环境是否是本地的)?像这样的东西

<choice>
    <when>
        <simple>{{is.local}} == true</simple>
        <to uri="direct:local.route"/>
    </when>
    <otherwise>
        <to uri="direct:server.route"/>
    </otherwise>
</choice>

但对于from子句

2 个答案:

答案 0 :(得分:1)

感谢MickaëlB使用配置文件的想法,我确实喜欢这个。

我创建了camel-route-local.xmlcamel-route.xml。第一个文件包含应在本地环境中工作的路由。第二 - 使用不适用于本地环境的端点运行的路由。文件camel-context.xml包含camelContext定义定义。

在我的主application-context.xml中,我在文件末尾添加了这些行

 <beans profile="default">
    <import resource="classpath:camel-route.xml"/>
    <import resource="classpath:camel-context.xml"/>
 </beans>

<beans profile="LOCAL">
    <import resource="classpath:camel-route-local.xml"/>
    <import resource="classpath:camel-context.xml"/>
</beans>

现在,如果我运行本地环境 - 也就是将spring配置文件设置为LOCAL - 它将加载camel-route-local.xml包含适用于本地环境的路由(我也完成了检查is.local)如果环境不是LOCAL - 也就是任何其他个人资料 - 它将加载主要路线。

答案 1 :(得分:0)

您只能将Java DSL用于此部分(创建简单的RouteBuilder)并根据您想要的任何内容初始化所需的“从”部分。

相关问题