java - 无法移除 Camel Quartz 路线
问题描述
我已经设置了一个这样的端点:
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);
但是,这里没有返回端点。
即使在执行此操作后,作业仍会继续按计划运行。删除路线时如何取消安排?
我正在使用带有石英 1.8.6 的骆驼石英 2.22.2
以下是 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
升级到 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();
推荐阅读
- c# - 从字符串 xx:xx:xx 格式中提取正则表达式
- android - 令牌过期后Android改造重复请求?
- c++ - 项目 C++ 中的日期参数
- wordpress - Google PageSpeed Insights API 无法连接到我的 Wordpress 博客以测试速度
- r - “实时”闪亮仪表板中的独特会话
- javascript - Magento mage-translation-storage 为空
- javascript - 具有二进制模式的列表过滤器
- c++ - 如何解决此错误没有匹配的呼叫功能?
- reactjs - TypeError:无法读取未定义的属性“日历”
- javascript - iPhone应用程序的React js问题(字符串和日期错误)