【发布时间】:2015-09-14 07:42:04
【问题描述】:
我想设置带有集群选项的 camel-quartz2 调度程序。
这是我当前的编码/配置:
package com.foo.bar.quartz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan({"com.foo.bar.quartz.camel"})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
package com.foo.bar.quartz;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ApplicationWebXml extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application
.showBanner(false)
.sources(Application.class);
return application;
}
}
package com.foo.bar.quartz.camel;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CamelScheduler extends RouteBuilder {
@Override
public void configure() throws Exception {
from("quartz2://group1/trigger1?cron=0/2+*+*+*+*+?&stateful=true")
.routeId("quartztimer")
.setHeader("ROUTING_KEY", simple("'trigger1'"))
.log(LoggingLevel.INFO, "Yeah quartz rocks, routingKey: ${header.ROUTING_KEY}");
}
}
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.jobFactory.class = org.quartz.simpl.SimpleJobFactory
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered=true
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost:3306/cntmx?characterEncoding=utf8
org.quartz.dataSource.myDS.user = blah
org.quartz.dataSource.myDS.password = hlab
org.quartz.dataSource.myDS.maxConnections = 12
我将此应用程序复制到 2 个单独的项目中,并将它们命名为quartz-demo-1、quartz-demo-2。
然后我在同一个 Apache 服务器上运行这两个应用程序。
两个调度程序每 2 秒同时触发一次:
2015-09-14 14:23:28 quartz-demo-2 [MyClusteredScheduler-camel-1-1_Worker-3] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
2015-09-14 14:23:28 quartz-demo-1 [MyClusteredScheduler-camel-1_Worker-3] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
2015-09-14 14:23:30 quartz-demo-1 [MyClusteredScheduler-camel-1_Worker-4] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
2015-09-14 14:23:30 quartz-demo-2 [MyClusteredScheduler-camel-1-1_Worker-4] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
2015-09-14 14:23:32 quartz-demo-1 [MyClusteredScheduler-camel-1_Worker-5] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
2015-09-14 14:23:32 quartz-demo-2 [MyClusteredScheduler-camel-1-1_Worker-5] INFO quartztimer - Yeah quartz rocks, routingKey: 'trigger1'
期望的行为是每两秒钟应该只有一个来自任一应用程序的触发来模拟故障转移。我该如何配置这种行为?即使从同一个石英表中读取数据,两个调度程序似乎也不知道彼此。
非常感谢您的帮助。
【问题讨论】:
标签: java apache-camel quartz-scheduler load-balancing