一般拿Timer和Quartz相比較的,簡直就是對Quartz的侮辱,兩者的功能根本就不在一個層級上,如本篇介紹的Quartz強大的集群機制,可以採用基於 sqlserver,mysql的集群方案,當然還可以在第三方插件的基礎上實現quartz序列化到熱炒的mongodb,redis,震撼力可想而知 ...
一般拿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】,完整的腳本如下:
1 -- this script is for SQL Server and Azure SQL 2 3 CREATE DATABASE [quartz] 4 GO 5 6 USE [quartz] 7 GO 8 9 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS]') AND OBJECTPROPERTY(id, N'ISFOREIGNKEY') = 1) 10 ALTER TABLE [dbo].[QRTZ_TRIGGERS] DROP CONSTRAINT FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS 11 GO 12 13 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISFOREIGNKEY') = 1) 14 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] DROP CONSTRAINT FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS 15 GO 16 17 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISFOREIGNKEY') = 1) 18 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS 19 GO 20 21 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISFOREIGNKEY') = 1) 22 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS 23 GO 24 25 IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS]') AND parent_object_id = OBJECT_ID(N'[dbo].[QRTZ_JOB_LISTENERS]')) 26 ALTER TABLE [dbo].[QRTZ_JOB_LISTENERS] DROP CONSTRAINT [FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS] 27 28 IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS]') AND parent_object_id = OBJECT_ID(N'[dbo].[QRTZ_TRIGGER_LISTENERS]')) 29 ALTER TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] DROP CONSTRAINT [FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS] 30 31 32 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_CALENDARS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 33 DROP TABLE [dbo].[QRTZ_CALENDARS] 34 GO 35 36 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_CRON_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 37 DROP TABLE [dbo].[QRTZ_CRON_TRIGGERS] 38 GO 39 40 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_BLOB_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 41 DROP TABLE [dbo].[QRTZ_BLOB_TRIGGERS] 42 GO 43 44 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_FIRED_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 45 DROP TABLE [dbo].[QRTZ_FIRED_TRIGGERS] 46 GO 47 48 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_PAUSED_TRIGGER_GRPS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 49 DROP TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] 50 GO 51 52 IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QRTZ_JOB_LISTENERS]') AND type in (N'U')) 53 DROP TABLE [dbo].[QRTZ_JOB_LISTENERS] 54 55 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_SCHEDULER_STATE]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 56 DROP TABLE [dbo].[QRTZ_SCHEDULER_STATE] 57 GO 58 59 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_LOCKS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 60 DROP TABLE [dbo].[QRTZ_LOCKS] 61 GO 62 IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QRTZ_TRIGGER_LISTENERS]') AND type in (N'U')) 63 DROP TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] 64 65 66 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_JOB_DETAILS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 67 DROP TABLE [dbo].[QRTZ_JOB_DETAILS] 68 GO 69 70 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_SIMPLE_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 71 DROP TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] 72 GO 73 74 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_SIMPROP_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 75 DROP TABLE [dbo].QRTZ_SIMPROP_TRIGGERS 76 GO 77 78 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QRTZ_TRIGGERS]') AND OBJECTPROPERTY(id, N'ISUSERTABLE') = 1) 79 DROP TABLE [dbo].[QRTZ_TRIGGERS] 80 GO 81 82 CREATE TABLE [dbo].[QRTZ_CALENDARS] ( 83 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 84 [CALENDAR_NAME] [NVARCHAR] (200) NOT NULL , 85 [CALENDAR] [IMAGE] NOT NULL 86 ) 87 GO 88 89 CREATE TABLE [dbo].[QRTZ_CRON_TRIGGERS] ( 90 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 91 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 92 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 93 [CRON_EXPRESSION] [NVARCHAR] (120) NOT NULL , 94 [TIME_ZONE_ID] [NVARCHAR] (80) 95 ) 96 GO 97 98 CREATE TABLE [dbo].[QRTZ_FIRED_TRIGGERS] ( 99 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 100 [ENTRY_ID] [NVARCHAR] (140) NOT NULL , 101 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 102 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 103 [INSTANCE_NAME] [NVARCHAR] (200) NOT NULL , 104 [FIRED_TIME] [BIGINT] NOT NULL , 105 [SCHED_TIME] [BIGINT] NOT NULL , 106 [PRIORITY] [INTEGER] NOT NULL , 107 [STATE] [NVARCHAR] (16) NOT NULL, 108 [JOB_NAME] [NVARCHAR] (150) NULL , 109 [JOB_GROUP] [NVARCHAR] (150) NULL , 110 [IS_NONCONCURRENT] BIT NULL , 111 [REQUESTS_RECOVERY] BIT NULL 112 ) 113 GO 114 115 CREATE TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] ( 116 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 117 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL 118 ) 119 GO 120 121 CREATE TABLE [dbo].[QRTZ_SCHEDULER_STATE] ( 122 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 123 [INSTANCE_NAME] [NVARCHAR] (200) NOT NULL , 124 [LAST_CHECKIN_TIME] [BIGINT] NOT NULL , 125 [CHECKIN_INTERVAL] [BIGINT] NOT NULL 126 ) 127 GO 128 129 CREATE TABLE [dbo].[QRTZ_LOCKS] ( 130 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 131 [LOCK_NAME] [NVARCHAR] (40) NOT NULL 132 ) 133 GO 134 135 CREATE TABLE [dbo].[QRTZ_JOB_DETAILS] ( 136 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 137 [JOB_NAME] [NVARCHAR] (150) NOT NULL , 138 [JOB_GROUP] [NVARCHAR] (150) NOT NULL , 139 [DESCRIPTION] [NVARCHAR] (250) NULL , 140 [JOB_CLASS_NAME] [NVARCHAR] (250) NOT NULL , 141 [IS_DURABLE] BIT NOT NULL , 142 [IS_NONCONCURRENT] BIT NOT NULL , 143 [IS_UPDATE_DATA] BIT NOT NULL , 144 [REQUESTS_RECOVERY] BIT NOT NULL , 145 [JOB_DATA] [IMAGE] NULL 146 ) 147 GO 148 149 CREATE TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] ( 150 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 151 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 152 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 153 [REPEAT_COUNT] [INTEGER] NOT NULL , 154 [REPEAT_INTERVAL] [BIGINT] NOT NULL , 155 [TIMES_TRIGGERED] [INTEGER] NOT NULL 156 ) 157 GO 158 159 CREATE TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] ( 160 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 161 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 162 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 163 [STR_PROP_1] [NVARCHAR] (512) NULL, 164 [STR_PROP_2] [NVARCHAR] (512) NULL, 165 [STR_PROP_3] [NVARCHAR] (512) NULL, 166 [INT_PROP_1] [INT] NULL, 167 [INT_PROP_2] [INT] NULL, 168 [LONG_PROP_1] [BIGINT] NULL, 169 [LONG_PROP_2] [BIGINT] NULL, 170 [DEC_PROP_1] [NUMERIC] (13,4) NULL, 171 [DEC_PROP_2] [NUMERIC] (13,4) NULL, 172 [BOOL_PROP_1] BIT NULL, 173 [BOOL_PROP_2] BIT NULL, 174 ) 175 GO 176 177 CREATE TABLE [dbo].[QRTZ_BLOB_TRIGGERS] ( 178 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 179 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 180 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 181 [BLOB_DATA] [IMAGE] NULL 182 ) 183 GO 184 185 CREATE TABLE [dbo].[QRTZ_TRIGGERS] ( 186 [SCHED_NAME] [NVARCHAR] (120) NOT NULL , 187 [TRIGGER_NAME] [NVARCHAR] (150) NOT NULL , 188 [TRIGGER_GROUP] [NVARCHAR] (150) NOT NULL , 189 [JOB_NAME