Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Cannot Reproduce
-
3.20.2
-
None
-
win10+jdk17+camel3.20.2+springboot2.7.8
Description
When I want to listen for events dynamically adding routes while the camel is running and use ScheduledRoutePolicy to manage the start and stop times of routes, I find that when dynamically created routes are set to noAutoStartup, this will not work. Here is the sample code:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class TestRouteBuilder extends RouteBuilder {
@Override
public void configure() {
from("direct:listenEvent").process(exchange -> getContext().addRoutes(new RouteBuilder() {
@Override
public void configure() {
SimpleScheduledRoutePolicy simpleScheduledRoutePolicy = new SimpleScheduledRoutePolicy();
simpleScheduledRoutePolicy.setRouteStartDate(new Date(System.currentTimeMillis() + 5000));
from("direct:" + System.currentTimeMillis()).routePolicy(simpleScheduledRoutePolicy).noAutoStartup().log("${body}");
}
}));
}
}