Reputation: 342
I need to restrict particular routes being added to the camel context based on some condition. Tried RoutePolicy.onStart -> but this method is being invoked after starting the route.
I need a way to to completely avoid the route being generated/added to camel context.
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;
}
}
Upvotes: 1
Views: 1466
Reputation: 55525
You need to set the route to autoStartup=false, and then in the onInit
method you can determine if it should be started anyway, and call its startRoute method.
Or another way is to configure CamelContext to have autoStartup=false
, and then you can have an Camel event lister bean that listen for CamelContextStartedEvent
, and then you trigger there to find out which routes you want to start, and call the camelContext.startRoute("nameOfRoute")
.
Upvotes: 3