Persistence of
quartz.net If the database-related configuration is not performed, the default execution mode is memory mode, the advantage is that the execution speed is fast, it is determined that the data cannot be stored and the downtime needs to start again.
Persistence requires only the following configuration (SQL Server for example)
NameValueCollection properties = new NameValueCollection (); Storage type properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, quartz"; Indicates that the prefix properties["quartz.jobStore.tablePrefix"] = "qrtz_"; Drive type properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, quartz" ; Data source name properties["Quartz.jobStore.dataSource"] = "MyDS"; Connection string properties["quartz.dataSource.myDS.connectionString"] = @ "Data source= (local); Initial Catalog=quartz; User Id=sa; Password=123 "; SQL Server version properties["Quartz.dataSource.myDS.provider"] = "SqlServer-20";
Client Server Mode
Quartz.net supports TCP communication, so you can have a schema scenario where all of the persisted tasks are hosted on the server and executed continuously, and you want to add tasks that can be added to the server database by the Client Management tool (which is, of course, the method in the Quartz.net framework), which results in a task scheduling service.
Server code example:
public class Remoteserverexample {public static void Run () {ILog log = Logmanager.getlogger (typeof (Remoteserverexam PLE)); NameValueCollection properties = new NameValueCollection (); <span style= "font-family:arial, Helvetica, Sans-serif;" >properties["quartz.scheduler.instanceName"] = "remoteserver";</span> properties["quartz.t Hreadpool.type "] =" Quartz.Simpl.SimpleThreadPool, Quartz "; properties["Quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; Set server properties["Quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Qu Artz "; properties["Quartz.scheduler.exporter.port"] = "555"; properties["quartz.scheduler.exporter.bindName"] = "Quartzscheduler"; properties["Quartz.scheDuler.exporter.channelType "] =" TCP "; properties["quartz.scheduler.exporter.channelName"] = "Httpquartz"; Deny remote//properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true"; Storage type properties["Quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, quartz"; Indicates that the prefix properties["quartz.jobStore.tablePrefix"] = "qrtz_"; Drive type properties["Quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerD Elegate, Quartz "; Data source name properties["Quartz.jobStore.dataSource"] = "MyDS"; Connection string properties["quartz.dataSource.myDS.connectionString"] = @ "Data source= (local); Initial Catal Og=quartz; User Id=sa; Password=123 "; SQL Server version properties["Quartz.dataSource.myDS.provider"] = "SqlServer-20"; Ischedulerfactory SF = new Stdschedulerfactory (properties); IScheduler sched = sf. Getscheduler (); sched. Start (); log. Info ("-------Server Start-----------------"); Thread.Sleep (Timespan.fromminutes (5)); Sched. Shutdown (TRUE); Log. Info ("-------Server off-----------------"); Schedulermetadata metaData = sched. GetMetaData (); log. Info ("Number of executions" + metadata.numberofjobsexecuted);}}
Client code example
[Persistjobdataafterexecution] [Disallowconcurrentexecution] public class Simplejob:ijob {public const string Message = "MSG"; private static readonly ILog log = Logmanager.getlogger (typeof (Simplejob)); public virtual void Execute (Ijobexecutioncontext context) { Jobkey Jobkey = context. Jobdetail.key; String message = Context. JobDetail.JobDataMap.GetString (Message); Log.infoformat ("{0} Execution time {1}", Jobkey, DateTime.Now.ToString ()); Log.infoformat ("msg: {0}", message); } }
public class Remoteclientexample {public static void Run () {ILog log = Logmanager.getlog Ger (typeof (Remoteclientexample)); NameValueCollection properties = new NameValueCollection (); properties["quartz.scheduler.instanceName"] = "remoteclient"; Set thread pool properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, quartz"; properties["Quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; Set remote connection properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = "Tcp://127.0.0.1:555/quartzscheduler"; Ischedulerfactory SF = new Stdschedulerfactory (properties); IScheduler sched = sf. Getscheduler (); Ijobdetail job = jobbuilder.create<simplejob> (). Withidentity ("Remotelyaddedjob", "Default"). Build (); Jobdatamap map = job. Jobdatamap; Map. Put ("msg", "message"); Itrigger trigger = Triggerbuilder.create (). Withidentity ("Remotelyaddedtrigger", "Default"). Forjob (Job. Key). Withcronschedule ("/5 * *?") * *") . Build (); Sched. Schedulejob (Job, trigger); Log. Info ("Add a scheduled task to the server"); } public string Name {get {return null;} } }
If the server is running on a single machine, there may be a business problem with the outage, so quartz.net provides the cluster configuration, which will be learned in the next article.
Quartz.net Learning Series (11)---quartz.net persistence and client server mode