使用一个主上下文启动多个骆驼



是什么是最好的方法(并允许)从主人骆驼的多个其他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))
            }
        }

我找不到一个骆驼的示例创建其他的示例...

这样做,它是循环的,并递归地称为....

您应该尝试使用Apache Karaf或Redhat Jboss Fuse等OSGI容器。
当您在此类容器中部署应用程序时,它将获得其自己的CamelContext。

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

我在保险领域工作,在该领域向个人,组和索赔等出售保险是单独的产品。如果我必须将所有这些模块部署为单独的战争/罐子,那么对路线的重构就会成为噩梦,因为在重构后,我需要确保一切正常。因此,我的需要是在需要时部署每个模块。为了实现这一目标,我尝试创建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绑定在一起时,春季容器将开始绑定下一个CamelContext路由时,它将开始引发异常。因此,从第二个CamelContext中,端点必须正确参考上下文,因为此时Spring容器获得了两个CamelContext引用,并与用户想要绑定路线的用户感到困惑。因此,如果您在端点上指定正确的骆驼上下文ID,则无问题。一切都可以正常工作。谢谢

最新更新