使用一个主上下文启动多个camelcontext

时间:2016-12-23 14:06:53

标签: apache-camel

从一个让我们说的主CamelContext启动多个其他camelContext的最佳方式(也是允许的)是什么:

我这样试试:

    @ContextName("master")
    public class MasterContext extends CdiCamelContext {


        @PostConstruct
        void customize() {

            setName("MASTER-Context");
            //some config  for the master.. properties...

            for (Service service : services){
               CamelContext ctx = new DefaultCamelContext() ;

               ctx.addRoutes(getRouteBuilder(someinfo))
            }

        }

我无法找到一个创建其他人的camelContext的示例......

并按照这种方式循环并以递归方式调用....

2 个答案:

答案 0 :(得分:0)

您应该尝试使用像Apache KarafRedHat JBoss Fuse这样的OSGi容器 在这样的容器中部署应用程序时,它会获得自己的CamelContext。

可以使用vm components或使用jmsActiveMQ组件的队列执行CamelContexts之间的通信。
CamelContexts创建由容器管理。容器还允许您在任何上下文中启动和停止单个路径,或者您可以使用ControlBus在应用程序中控制它们。

答案 1 :(得分:-3)

我在保险领域工作,向个人,集团,即公司和索赔等销售保险被视为单独的产品。但是所有这些模块可能是单个产品的一部分,其中单个camelContext工作正常。如果我必须部署所有这些模块作为单独的战争/ Jar然后重构路线变成了噩梦,因为在重构后我需要确保一切工作都很好。所以我需要在需要时部署每个模块。为了实现这一点,我尝试创建routeContext,但是routeContext有自己的限制,所以我为每个模块创建了单独的camelContext,为此你需要在创建端点,代理等时引用正确的camelContext,否则你将在运行时遇到很多问题。示例: -

 <camel:proxy id="abc" camelContextId="camelContext-main" serviceInterface="com.abc" serviceUrl="direct:abc"/>
<camel:endpoint id="xyz" camelContextId="camelContext-second" uri="bean:klm"></camel:endpoint>
<camel:endpoint id="123" camelContextId="camelContext-main" uri="bean:dddd"></camel:endpoint>
<camel:endpoint id="ssss" camelContextId="camelContext-second" uri="bean:ttt"></camel:endpoint>

如果你有多个camelContext,那么spring将使用第一个camelContext成功绑定所有路由,当spring容器将开始绑定下一个camelContext路由时,它将开始抛出异常。 因此,从第二个camelContext开始,端点必须正确引用上下文,因为此时spring容器有两个camelContext引用,并且混淆了哪个用户想要绑定路由。因此,如果您将在端点指定正确的camel context id,那么没有问题。一切都会好起来的。谢谢

相关问题