我正在尝试在不同的camel上下文中组合几个camel路由,以避免组件名称冲突。我知道如何在从CamelConfiguration扩展的相同Context中配置几个RouteBuilder类
@Configuration
public class CamelConfig extends CamelConfiguration {
@Override
public List<RouteBuilder> routes() {
// here I create the RouteBuilder List and the return it
}
但是如何使用Java Configuration在一个camel上下文和其他camel上下文中的其他路由中创建一些路由?
答案 0 :(得分:1)
您可以在一个 Camel上下文中添加外部XML文件中定义的许多 Camel Routes 如下所示:
您可以在新的xml文件中创建路由(即 routes1-config.xml ):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- this is an included XML file where we only the the routeContext -->
<routeContext id="routes1" xmlns="http://camel.apache.org/schema/spring">
<!-- we can have a route -->
<route id="cool">
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
<!-- and another route, you can have as many your like -->
<route id="bar">
<from uri="direct:bar"/>
<to uri="mock:bar"/>
</route>
</routeContext>
</beans>
然后在主camel xml文件中的上下文中导入并引用它,如下所示:
<!-- import the routes from another XML file -->
<import resource="routes1-config.xml"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- refer to a given route to be used -->
<routeContextRef ref="routes1"/>
<!-- we can of course still use routes inside camelContext -->
<route id="inside">
<from uri="direct:inside"/>
<to uri="mock:inside"/>
</route>
</camelContext>
有关详细信息,请查看Apache Camel http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html
的官方参考文档答案 1 :(得分:0)
一个CamelConfiguration
课程会创建一个CamelContext
。解决方案是拥有多个这样的子类(或类似的)。
答案 2 :(得分:0)
您可以使用NMR(规范化消息路由器),http://camel.apache.org/nmr.html并将每个项目中的路由公开为camel配置作为NMR路由,然后使用nmr:routename通过统一的Java方法使用它。