1、camel + quartz2 pom配置
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
</dependency>2、camel实现quartz2路由
from("quartz2:test?cron=0/5 * * * * ?")
.id("Test")
.log("Message received");3、为quartz2引入quartz.properties配置文件,采用xml配置的方式,创建spring-camel.xml文件,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- QuartzProperties -->
<bean id="quartz2" class="org.apache.camel.component.quartz2.QuartzComponent">
<property name="startDelayedSeconds" value="5"/>
<property name="propertiesFile" value="quartz.properties"/>
</bean>
</beans>4、引入新创建的xml配置文件
@SpringBootApplication
@ComponentScan({"com.test"})
@ImportResource(locations = {"classpath:spring-camel.xml"})
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}5、 quartz.properties配置文件
#============================================================================
#使用StdSchedulerFactory的 getScheduler()方法创建的scheduler实例名称,在同一个程序中可以根据该名称来区分scheduler。
#如果在集群环境中使用,必须使用同一个名称——集群环境下”逻辑”相同的scheduler。
org.quartz.scheduler.instanceName=quartzScheduler
#scheduler实例的标志id,必须是全局唯一的,即使在集群环境中”逻辑”相同的scheduler。或者可以使用“SYS_PROP”通过系统属性设置id。设置为AUTO让Quartz自动生成ID
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool 线程池配置
#============================================================================
#没有实现自己的线程池情况下,通常使用org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
#连接数
org.quartz.threadPool.threadCount=10
#表示线程优先级,可以为1~10 默认为Thread.NORM_PRIORITY (5)
org.quartz.threadPool.threadPriority=5
#是否自创建父线程 非集群时可不写 默认为false,集群时必须设置为true
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
#============================================================================
# Configure JobStore 持久化配置
#============================================================================
#持久化方式配置,可配置内存式(org.quartz.simpl.RAMJobStore),内存式服务重启会失效
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#持久化方式配置数据驱动,标准数据库(如MYSQL)
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#quartz相关数据表前缀名
org.quartz.jobStore.tablePrefix = QRTZ_
#开启分布式部署
org.quartz.jobStore.isClustered = true
#分布式节点有效性检查时间间隔,单位:毫秒
org.quartz.jobStore.clusterCheckinInterval = 20000
#设置jobStore处理未按时触发的Job的数量
org.quartz.jobStore.maxMisfiresToHandleAtATime = 1
#当一个触发器被判定没有触发之前,调度器能承受一个触发器再次触发的一个毫秒级数字
org.quartz.jobStore.misfireThreshold = 120000
#数据库隔离级别 mysql下设置为true容易出现死锁
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.dataSource=QRTZDB
org.quartz.dataSource.QRTZDB.driver= com.mysql.jdbc.Driver
org.quartz.dataSource.QRTZDB.maxConnections=30
org.quartz.dataSource.QRTZDB.URL=jdbc:mysql://127.0.0.1/test
org.quartz.dataSource.QRTZDB.user=root
org.quartz.dataSource.QRTZDB.password=root
版权声明:本文为weixin_37497666原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。