Quartz.net persistence and cluster-(4), quartz.net Cluster

Source: Internet
Author: User

Quartz.net persistence and cluster-(4), quartz.net Cluster
Introduction

In actual use of quartz.net. Persistence ensures that the job is not lost after the instance is restarted, the cluster can balance the server pressure and solve the single point of failure.

Quartz.net is easy to configure in these two parts.

I. Persistence

The persistence of quartz.net stores job and trigger information in the database to solve the loss of memory storage restart.

1: Download the SQL script.

Https://github.com/quartznet/quartznet/blob/master/database/tables/tables_sqlServer. SQL

2: Create a database and execute the script.

QRTZ_BLOB_TRIGGERS is a trigger stored as Blob.

QRTZ_CALENDARS stores calendar information. quartz.net can specify a calendar time range.

QRTZ_CRON_TRIGGERS cron expression trigger.

QRTZ_JOB_DETAILS job details.

The row lock table of the QRTZ_LOCKS cluster for synchronization mechanism

QRTZ_SCHEDULER_STATE instance information, which is used in multiple clusters.

3: quartz.net Configuration
/// Storage type properties ["quartz. jobStore. type "] =" Quartz. impl. adoJobStore. jobStoreTX, Quartz "; // indicates the prefix properties [" quartz. jobStore. tablePrefix "] =" QRTZ _ "; // driver 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 = jobschedalog; User ID = sa; Password = 123465 "; // sqlserver properties [" quartz. dataSource. myDS. provider "] =" SqlServer-20 ";
4. Start the client.
  var properties = JobsManager.GetProperties();            var schedulerFactory = new StdSchedulerFactory(properties);            scheduler = schedulerFactory.GetScheduler();            scheduler.Start();            //var job = JobBuilder.Create<MonitorJob>()            //    .WithIdentity("test", "value")            //    .Build();            //var trigger = (ICronTrigger) TriggerBuilder.Create()            //    .WithIdentity("test", "value")            //    .WithCronSchedule("0 0/5 * * * ?")            //    .Build();            //scheduler.ScheduleJob(job, trigger);
5: Supplement

1: After persistence, the job can only be added once (the database already exists), so you cannot execute the write operation to add a job. In this case, a management tool is required to dynamically add operations.

2: quartz.net supports SQL server, sqlite, mysql, oracle, and mongodb (unofficial version ).

 

Ii. Cluster

Deployment diagram:

 

 

The cluster mode of quartz.net depends on the database table, so you need to configure it persistently. Cluster nodes do not communicate with each other. This distributed architecture facilitates horizontal scaling.

 

1: apart from the number of thread pools, instanceId can be different. The configurations of each node must be the same.

2: the system time of nodes in the cluster is the same.

3: multithreading and cluster. Quartz.net uses database locks to prevent repeated job execution.

The source code is in DBSemaphore. cs, UpdateLockRowSemaphore. cs, StdRowLockSemaphore. cs

4: After clustering, after a node fails, the remaining nodes can ensure that the job continues to run.

 

Start the instance after it is configured.

   //cluster            properties["quartz.jobStore.clustered"] = "true";            properties["quartz.scheduler.instanceId"] = "AUTO";

 

Simple management interface:

 

Author: Mr. mushroom Source: http://www.cnblogs.com/mushroom/p/4231642.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.