如何解决带有 mongodb 的石英调度程序在集群环境中不起作用
我们有一个带有 Quartz Scheduler 的 Spring Boot 应用程序来运行预定作业。
这是用于quartz的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>com.novemberain</groupId>
<artifactId>quartz-mongodb</artifactId>
<version>2.0.0</version>
<systemPath>${basedir}/lib/quartz-mongodb.jar</systemPath>
<scope>system</scope>
</dependency>
调度程序设置
@Bean
public SchedulerFactoryBean quartzScheduler() {
MongoClientURI uri = new MongoClientURI(mongodbURI);
try {
SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
quartzScheduler.setOverwriteExistingJobs(true);
quartzScheduler.setSchedulerName("Merlin-Quartz-Scheduler");
quartzScheduler.setJobFactory(autowiringSpringBeanJobFactory);
Properties quartzProperties = new Properties();
quartzProperties.setProperty("org.quartz.scheduler.instanceName","Quartz_Instance");
quartzProperties.setProperty("org.quartz.scheduler.instanceId","AUTO");
quartzProperties.setProperty("org.quartz.threadPool.threadCount",10);
quartzProperties.setProperty("org.quartz.jobStore.mongoUri",mongodbURI);
quartzProperties.setProperty("org.quartz.jobStore.class","com.novemberain.quartz.mongodb.MongoDBJobStore");
quartzProperties.setProperty("org.quartz.jobStore.dbName",uri.getDatabase());
quartzProperties.setProperty("org.quartz.jobStore.collectionPrefix","quartz");
quartzProperties.setProperty("org.quartz.jobStore.misfireThreshold","0");
quartzProperties.setProperty("org.quartz.jobStore.isClustered","true");
quartzProperties.setProperty("org.quartz.jobStore.checkInErrorHandler","com.novemberain.quartz.mongodb.cluster.NoOpErrorHandler");
quartzScheduler.setQuartzProperties(quartzProperties);
return quartzScheduler;
} catch (Exception e) {
logger.error("Quartz Scheduler can not be initialized,the error is ",e);
return null;
}
}
这是我们安排工作的方式
protected static Trigger createCronTrigger(String triggerName,String groupName,Date startTime,Date endTime,String cronExpression,int misFireInstruction){
CronTrigger cronTrigger = TriggerBuilder.newTrigger()
.withIdentity(triggerName,groupName)
.startAt(startTime)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing())
.endAt(endTime)
.build();
return cronTrigger;
}
问题描述 :- 有时调度程序没有被意外触发,这种情况在我们转移到集群设置后开始发生,在单节点中它工作正常。
我们在日志中找不到任何错误,感谢您对此的任何帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。