I was debugging Camel. It CamelContext.startRoute(String)does not seem to start the route with autoStartup = false.
The correct way to start a route:
ServiceHelper.startService(route.getConsumer());
RoutePolicy:
public class MyRoutePolicy implements RoutePolicy {
@Override
public void onInit(Route route) {
if(shouldStartRoute(route)) {
ServiceHelper.startService(route.getConsumer());
}
}
}
, route.getConsumer() null. , Camel ServiceHelper.startService(consumer). , :
public class MyRoutePolicy extends EventNotifierSupport implements RoutePolicy {
private final Collection<Route> routes = new HashSet<>();
@Override
public void onInit(Route route) {
routes.add(route);
CamelContext camelContext = route.getRouteContext().getCamelContext();
ManagementStrategy managementStrategy = camelContext.getManagementStrategy();
if (!managementStrategy.getEventNotifiers().contains(this)) {
managementStrategy.addEventNotifier(this);
}
}
@Override
public void notify(EventObject event) throws Exception {
if(event instanceof CamelContextStartedEvent) {
for(Route route : routes) {
if(shouldStartRoute(route)) {
ServiceHelper.startService(route.getConsumer());
}
}
}
}
}