如何解决Spring Quartz Scheduler在ECS群集中不起作用
我正在使用 Spring Boot(2.2.7.RELEASE), Quartz Scheduler(2.3.2)开发调度应用程序。应用程序根据负载部署在 AWS ECS群集中并在多个EC2实例中运行。我正在使用 AWS RDS Mysql 数据库并创建了必需的石英表。我已将以下属性文件用于石英。
quartz.properties -
org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
org.quartz.threadPool.threadPriority = 5
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000
应用程序启动日志-
2020-10-13 23:33:02.853 INFO 938 --- [ main] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.2 created.
2020-10-13 23:33:02.856 INFO 938 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : Using db table-based data access locking (synchronization).
2020-10-13 23:33:02.858 INFO 938 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : JobStoreCMT initialized.
2020-10-13 23:33:02.859 INFO 938 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' 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.springframework.scheduling.quartz.LocalDataSourceJobStore'
- which supports persistence. and is not clustered.
问题是多个EC2实例正在同时接管同一作业。因此会得到错误的结果。
有人可以让我知道我在这里想念的吗?我要做的是使其在ECS集群中工作。每次启动Spring应用程序时,它都会显示日志消息未集群。
解决方法
此问题已解决。我已将以下配置详细信息添加到application.properties
文件中,并删除了quartz.properties
文件
spring.quartz.job-store-type = jdbc
spring.quartz.properties.org.quartz.scheduler.instanceName = MyClusteredScheduler
spring.quartz.properties.org.quartz.jobStore.isClustered = true
spring.quartz.properties.org.quartz.scheduler.instanceId = AUTO
spring.quartz.properties.org.quartz.jobStore.useProperties = true
spring.quartz.properties.org.quartz.jobStore.tablePrefix = QRTZ_
spring.quartz.properties.org.quartz.jobStore.isClustered = true
spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval = 20000
现在,批处理作业在ECS中运行正常,并且一次只有一个作业在ECS集群中运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。