Camel只在错误的时间

时间:2018-03-21 11:02:24

标签: spring-boot apache-camel quartz-scheduler

我有一个带有几个camel路由的Spring启动应用程序,它应该基于quartz2的CronTrigger启动。出于某种原因,只有首先安排的路线才会开始,但是从最后一条路线的预定时间开始。

  1. 路线一:mytime - 1h
  2. 路线二:mytime
  3. 在我的时间,只开始路线一。

    我做了一个小例子。因为我的路由应该检查数据库表的内容并导出它的一部分,在我的例子中,路由将检查表并记录在属性中的列集中找到的最近日期。

    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}
    

    日志:

      

    配置的导出路由:MonthProcessingRoute - schedule:   quartz2:// CronTrigger?cron = 0 39 * * *?

         

    配置的导出路由:WeekProcessingRoute - schedule:quartz2:// CronTrigger?cron = 0 41 * * *?

         

    2018-03-20 05:37:33 INFO tryouts-spring-camel ivana.StartUp - -    - 在2.507秒内启动启动(JVM运行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 * * *?

         

    数据库表月份中发现的最新日期:2017-11-05 15:31:00.0

1 个答案:

答案 0 :(得分:1)

您应该确保为每个Camel路由使用唯一的triggerName / groupName。看起来您在两个路由中使用相同的名称CronTrigger。将其更改为唯一名称,它应该有效。