Apache camel 基于某些条件禁用添加到骆驼上下文的路由

Apache camel 基于某些条件禁用添加到骆驼上下文的路由,apache-camel,jbossfuse,fuseesb,blueprint-osgi,Apache Camel,Jbossfuse,Fuseesb,Blueprint Osgi,我需要根据某些条件限制添加到camel上下文中的特定路由。已尝试RoutePolicy.onStart->但此方法在启动路由后被调用 我需要一种方法来完全避免生成/添加到camel上下文中的路由 private List<String> eligibleRoutes; @Override public void onStart(Route route) { LOGGER.info("onInit for {}", route.getId()); if (is

我需要根据某些条件限制添加到camel上下文中的特定路由。已尝试RoutePolicy.onStart->但此方法在启动路由后被调用

我需要一种方法来完全避免生成/添加到camel上下文中的路由

 private List<String> eligibleRoutes;

 @Override
  public void onStart(Route route) {
    LOGGER.info("onInit for {}", route.getId());
    if (isCollectionNotEmpty(eligibleRoutes))
    {
      LOGGER.info("route-start eligibility for route {}", route.getId());
      if (eligibleRoutes.contains(route.getId()))
      {
        LOGGER.info("Route-start is set to ELIGiBLE for {}", route.getId());
      }else{
        LOGGER.info("Route-start is set to NOT ELIGiBLE for {}", route.getId());

        route.getRouteContext().getCamelContext().stopRoute(route.getId());
        boolean status = route.getRouteContext().getCamelContext().removeRoute(route.getId());
        return;
      }
}
private-List-eligblerroutes;
@凌驾
公共void onStart(路由){
info(“onInit for{}”,route.getId());
如果(isCollectionNotEmpty(EligiblerRoutes))
{
info(“路由{}的路由开始资格”,route.getId());
if(eligibleRoutes.contains(route.getId()))
{
info(“路由开始被设置为符合{}”,Route.getId());
}否则{
info(“路由开始设置为不符合{}”,Route.getId());
route.getRouteContext().getCamelContext().stopRoute(route.getId());
布尔状态=route.getRouteContext().getCamelContext().removeRoute(route.getId());
返回;
}
}

您需要将路由设置为autoStartup=false,然后在
onInit
方法中,您可以确定是否应该启动路由,并调用其startRoute方法


或者另一种方法是将CamelContext配置为具有
autoStartup=false
,然后您可以拥有一个CamelContextStartedEvent侦听CamelContextStartedEvent的CamelContext列表器bean,然后您在那里触发,以找出您想要启动的路由,并调用
CamelContext.startRoute(“nameOfRoute”)

您是在使用Spring集成还是自己创建和管理
CamelContext
呢?如何将路由添加到代码中的上下文中?使用blueprint创建CamelContext和路由。我有多个路由,只有在符合条件时才需要使它们可见。怎么样?谢谢Claus。我尝试了使用C的EventNotifierSupportAMELCONTEXTSTARTED事件,它就像一个符咒。