无法删除骆驼石英路线

时间:2019-01-07 16:00:49

标签: java apache-camel quartz-scheduler

我已经这样设置了一个端点:

from("quartz://GroupName/TimerName?stateful=true&cron=0 0/1 * * * ?")
.to("someProcessorBean");

为了确保没有静态端点,我这样做:

for (Endpoint endpoint : camelContext.getEndpoints()) {
  camelContext.removeEndpoint(endpoint);
}

当尝试以编程方式删除路线时,我正在执行以下操作:

camelContext.stop();
camelContext.removeRoute(routeId);

但是,这里没有返回端点。

即使执行此操作,作业仍将按计划运行。删除路线时如何取消行程安排?

我正在使用骆驼石英2.22.2和石英1.8.6

以下是关闭后再启动Context的日志。

关闭端点

12:22:13,008 DEBUG [DefaultManagementAgent] Unregistered MBean with ObjectName: org.apache.camel:context=CamelContext-MyContext_6.1.1-SNAPSHOT,type=endpoints,name="quartz://MY_GROUP/MY_NAME\?cron=0+0%2F1+\*+\*+\*+%3F&stateful=true"
12:22:13,008 INFO  [SpringCamelContext] Apache Camel 2.22.2 (CamelContext: CamelContext-MyContext_6.1.1-SNAPSHOT) is shutting down
12:22:13,008 INFO  [DefaultShutdownStrategy] Starting to graceful shutdown 1 routes (timeout 300 seconds)

停车路线

12:22:13,033 INFO  [DefaultShutdownStrategy] Starting to graceful shutdown 1 routes (timeout 300 seconds)
12:22:13,033 DEBUG [DefaultExecutorServiceManager] Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy@3a44287c with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@3fc7873f[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask]
12:22:13,034 DEBUG [DefaultShutdownStrategy] There are 1 routes to shutdown
12:22:13,034 INFO  [DefaultShutdownStrategy] Graceful shutdown of 1 routes completed in 0 seconds
12:22:13,034 INFO  [SpringCamelContext] Route: MY_CATEGORY.MY_NAME is stopped, was consuming from: quartz://MY_GROUP/MY_NAME?cron=0+0%2F1+*+*+*+%3F&stateful=true
12:22:13,034 DEBUG [RouteService] Shutting down services on route: MY_CATEGORY.MY_NAME
12:22:13,034 DEBUG [RouteService] Shutting down child service on route: MY_CATEGORY.MY_NAME -> FatalFallbackErrorHandler[Channel[DelegateSync[com.crlcorp.oasis.routing.utils.LauncherErrorHandler@7ccfd046]]]
12:22:13,034 DEBUG [RouteService] Shutting down child service on route: MY_CATEGORY.MY_NAME -> DelegateSync[com.crlcorp.oasis.routing.utils.LauncherErrorHandler@7ccfd046]
12:22:13,034 DEBUG [RouteService] Shutting down child service on route: MY_CATEGORY.MY_NAME -> Channel[DelegateSync[com.crlcorp.oasis.routing.utils.LauncherErrorHandler@7ccfd046]]
12:22:13,034 INFO  [SpringCamelContext] Route: MY_CATEGORY.MY_NAME is shutdown and removed, was consuming from: quartz://MY_GROUP/MY_NAME?cron=0+0%2F1+*+*+*+%3F&stateful=true

以“无路线”开始上下文

12:22:13,078 INFO  [QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v1.8.6) 'DefaultQuartzScheduler-CamelContext-MyContext_6.1.1-SNAPSHOT' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

12:22:13,078 INFO  [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler-CamelContext-MyContext_6.1.1-SNAPSHOT' initialized from an externally provided properties instance.
12:22:13,078 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.8.6
12:22:13,078 DEBUG [QuartzComponent] Using SchedulerFactory org.quartz.impl.StdSchedulerFactory@5efaa50e to get/create Scheduler org.quartz.impl.StdScheduler@6d39162c(0x6d39162c)
12:22:13,078 INFO  [QuartzComponent] Starting Quartz scheduler: DefaultQuartzScheduler-CamelContext-MyContext_6.1.1-SNAPSHOT
12:22:13,078 INFO  [QuartzScheduler] Scheduler DefaultQuartzScheduler-CamelContext-MyContext_6.1.1-SNAPSHOT_$_NON_CLUSTERED started.
12:22:13,078 DEBUG [DefaultManagementLifecycleStrategy] Load performance statistics disabled
12:22:13,078 INFO  [SpringCamelContext] Total 0 routes, of which 0 are started
12:22:13,078 INFO  [SpringCamelContext] Apache Camel 2.22.2 (CamelContext: CamelContext-MyContext_6.1.1-SNAPSHOT) started in 0.036 seconds

石英作业从死里复生

12:22:13,507 DEBUG [SimpleThreadPool] WorkerThread is shut down.
12:23:00,002 DEBUG [SimpleJobFactory] Producing instance of Job 'DEFAULT.quartz-endpoint1', class=org.apache.camel.component.quartz.StatefulCamelJob
12:23:00,002 DEBUG [JobRunShell] Calling execute on job DEFAULT.quartz-endpoint1
12:23:00,002 DEBUG [CamelJob] Looking up existing QuartzEndpoint with trigger MY_NAME.MY_GROUP
12:23:00,002 DEBUG [QuartzEndpoint] Firing Quartz Job with context: JobExecutionContext: trigger: 'MY_GROUP.MY_NAME job: DEFAULT.quartz-endpoint1 fireTime: 'Mon Jan 07 12:23:00 CST 2019 scheduledFireTime: Mon Jan 07 12:23:00 CST 2019 previousFireTime: 'Mon Jan 07 12:22:00 CST 2019 nextFireTime: Mon Jan 07 12:24:00 CST 2019 isRecovering: false refireCount: 0

1 个答案:

答案 0 :(得分:1)

选项1

升级到camel-quartz2,而不是camel-quartz。

选项2

问题与Quartz组件创建两个调度程序,并且仅在停止路由时关闭一个调度程序有关。这可能是由于路由是有状态的。为了解决此问题,您可以手动访问与该组件有关的所有调度程序并停止所有作业。

log.info("Removing existing endpoints");
for (Endpoint endpoint : camelContext.getEndpoints()) {
  log.info("Removing: " + endpoint.getEndpointUri());

  if (endpoint instanceof QuartzEndpoint) {
    QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;

    SchedulerFactory factory = quartzEndpoint.getComponent().getFactory();
    log.debug("Found factory " + factory);

    @SuppressWarnings("unchecked")
    Collection<Scheduler> allSchedulers = factory.getAllSchedulers();
    for (Scheduler scheduler : allSchedulers) {
      log.debug("Found Quartz Scheduler" + scheduler.getSchedulerName());
      for (String groupName : scheduler.getJobGroupNames()) {
        for (String jobName : scheduler.getJobNames(groupName)) {
          log.debug(String.format("Unscheduling job %s.%s", groupName, jobName));
          scheduler.deleteJob(jobName, groupName);
        }
      }
    }
  }
  camelContext.removeEndpoint(endpoint);
}

log.info("Stopping Camel Context");
camelContext.stop();

log.info("Removing existing routes");
RoutesDefinition routes = getRouteCollection();
routes.getOnExceptions().clear();
for (RouteDefinition route : routes.getRoutes()) {
  String routeId = route.getId();
  try {
    log.info("Removing: " + routeId);
    camelContext.removeRoute(routeId);
  } catch (Exception e) {
    log.warn("Could not stop route" + routeId + ": " + e.getMessage());
  }
}
routes.getRoutes().clear();