Reputation: 705
I have a Spring boot application with several camel routes that should start based on a quartz2's CronTrigger. For some reason, only the the route scheduled first is ever started, but it starts at the time scheduled for the last route.
Only route one is started, at mytime.
I have made a minimal example. Because my routes are supposed to check the contents of a database table and export part of it, in my example the routes will check the table and log the most recent date found in a column set in the properties.
Routebuilder:
/**
* Starts a list of routes that have been scheduled in application.yml
*/
@Component
public class ScheduledRoutesRouteBuilder extends SpringRouteBuilder {
private static final Logger LOG = LoggerFactory.getLogger(ScheduledRoutesRouteBuilder.class);
private static final String BEAN_CHECKDB = "bean:checkDBBean?method=getFirstRecord(%s, %s)";
@Autowired
private RoutesDefinition routesDefinition;
@Override
public void configure() throws Exception {
routesDefinition.getScheduledRoutes().stream()
.forEach(route -> createScheduledRoute(route));
}
private void createScheduledRoute(RouteDefinition aRoute) {
from(aRoute.getSchedule())
.routeId(aRoute.getRouteId())
.log(LoggingLevel.INFO, LOG, "Kickstarting export route: " + aRoute.getRouteId() + " - schedule: " + aRoute.getSchedule())
.to(String.format(BEAN_CHECKDB, aRoute.getDbTableName(), aRoute.getReferenceDateColumnName()));
System.out.println("Configured export route: " + aRoute.getRouteId() + " - schedule: " + aRoute.getSchedule());
}
}
application.yml:
# Schedules
scheduleFirst: 0 39 * * * ?
scheduleSecond: 0 41 * * * ?
scheduledRoutes:
- routeId: MonthProcessingRoute
dbTableName: month
referenceDateColumnName: acceptatiedatum
schedule: quartz2://CronTrigger?cron=${scheduleFirst}
- routeId: WeekProcessingRoute
dbTableName: week
referenceDateColumnName: acceptatiedatum
schedule: quartz2://CronTrigger?cron=${scheduleSecond}
Log:
Configured export route: MonthProcessingRoute - schedule: quartz2://CronTrigger?cron=0 39 * * * ?
Configured export route: WeekProcessingRoute - schedule: quartz2://CronTrigger?cron=0 41 * * * ?
2018-03-20 05:37:33 INFO tryouts-spring-camel ivana.StartUp - - - Started StartUp in 2.507 seconds (JVM running for 3.238)
2018-03-20 05:41:00 INFO tryouts-spring-camel ivana.routebuilders.ScheduledRoutesRouteBuilder - - - Kickstarting export route: MonthProcessingRoute - schedule: quartz2://CronTrigger?cron=0 39 * * * ?
Most recent date found in database table month: 2017-11-05 15:31:00.0
Upvotes: 0
Views: 937
Reputation: 55750
You should make sure to use unique triggerName/groupName for each of your Camel routes. It looks like you use the same name CronTrigger
in both routes. Change that to be unique names, and it should work.
Upvotes: 1