一般拿Timer和Quartz相比较的,简直就是对Quartz的侮辱,两者的功能根本就不在一个层级上,如本篇介绍的Quartz强大的集群机制,可以采用基于
sqlserver,mysql的集群方案,当然还可以在第三方插件的基础上实现quartz序列化到热炒的mongodb,redis,震撼力可想而知,接下来本篇就和大家聊
一聊怎么搭建基于sqlserver的quartz集群,实现这么一种双机热备的强大功能。
一:下载sqlserver版的建表脚本
首先大家可以通过github上搜索quartz的源代码,在源码项目的/database/tables目录下,可以找到firebird,oracle,mysql,sqlserver等建库脚本,
本篇只需拿取sqlserver版本即可。 https://github.com/quartznet/quartznet/tree/master/database/tables 如下图所示
从上面的截图中可以看到,我接下来要做的事情就是增加一个你需要创建的database名字,这里取为:【quartz】,完整的脚本如下:
(dbo.sysobjects ) ) = 1) . FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS (dbo.sysobjects ) ) = 1) . FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS (dbo.sysobjects ) ) = 1) . FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS (dbo.sysobjects ) ) = 1) . FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS (sys.foreign_keys (N) )) .(sys.foreign_keys (N) )) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(sys.objects (N) )) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(sys.objects (N) )) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .(dbo.sysobjects ) ) = 1) .QRTZ_SIMPROP_TRIGGERS (dbo.sysobjects ) ) = 1) .. ( (120) NOT NULL , (200) NOT NULL , ) . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , (120) NOT NULL , (80) 95 ) . ( (120) NOT NULL , (140) NOT NULL , (150) NOT NULL , (150) NOT NULL , (200) NOT NULL , , , , (16) NOT NULL, (150) NULL , (150) NULL , , ) . ( (120) NOT NULL , () . ( (120) NOT NULL , (200) NOT NULL , , ) . ( (120) NOT NULL , () . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , (250) NULL , (250) NOT NULL , , , , , ) . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , , , ) . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , (512) NULL, (512) NULL, (512) NULL, , , , , (13,4) NULL, (13,4) NULL, , , 174 ) . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , ) . ( (120) NOT NULL , (150) NOT NULL , (150) NOT NULL , (150) NOT NULL , (150) NOT NULL , (250) NULL , , , , (16) NOT NULL , (8) NOT NULL , , , (200) NULL , , ) . ( , ) . ( , , ) . ( , ) . ( , ) . ( , ) . ( , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) .QRTZ_BLOB_TRIGGERS ( , , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) . ( , , ) IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP) IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP) IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME) IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP) IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE) IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE) IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE) IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME) IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME) IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME) IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE) IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE) IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME) IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY) IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP) IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP) IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP) 370 GO
View Code
二:配置quartz的集群参数
当我们写var scheduler = StdSchedulerFactory.GetDefaultScheduler()这段代码的时候,如果大家看过源码的话,会知道这个GetScheduler的
过程中有一个初始化方法【Instantiate】方法,此方法中你会发现在做DBProvider的时候会需要几个参数来初始化DB的,比如下面看到的几个标红属性。