2014-10-01 75 views
1

我想在不同的骆驼上下文中分组几个骆驼路线,以避免组件名称冲突。我知道如何配置几个RouteBuilder班延长从CamelConfiguration这样骆驼 - 如何与java配置多个上下文

@Configuration 
    public class CamelConfig extends CamelConfiguration { 

    @Override 
    public List<RouteBuilder> routes() { 
     // here I create the RouteBuilder List and the return it 
    } 

同样的情况下,但我怎么能有使用Java配置在一个骆驼背景部分航线等航线在其他情况下的骆驼?

回答

0

one CamelConfiguration class创建一个CamelContext。解决方案是有多个这样的子类(或类似的)。

+0

非常感谢您的答复皮特!但我该怎么做?基本上我有一个属性文件,我定义了一个RouteBuilder类的列表。然后路由中的代码迭代该文件。我想要的是具有RouterBuilder类列表的同一个文件,但是在它自己的Camel上下文中创建每个RouteBuilder。那可能吗?可能以某种方式修改CamelConfiguration类,但我不知道如何去做。再次感谢! – 2014-10-02 13:21:53

0

您可以使用NMR(Normalized Message Router),http://camel.apache.org/nmr.html,并将这些项目中的每个项目的路由公开为NMR路由,然后通过使用nmr:routename的统一Java方法使用它。

1

你可以在短短一个骆驼语境中添加外部XML文件定义了许多骆驼路线 为波纹管的例子:

您可以在一个新的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> 

然后导入,并引用它的主要骆驼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的骆驼检查的官方参考文档http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html