Thursday, June 21, 2012

Automation made easy

Ever found the need to automate certain functionality other than for integration requirements using architectures such as Biztalk server or SSIS packages. Then you would realize how cumbersome it can be setting up triggers and working with different threads.

Introducing Quartz.NET:

 “Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems”

I’ve supplied a very basic sample solution comprising of a console and MVC project. The console application can be run manually or installed as a windows service, and the MVC application is to demonstrate the crystal quartz interface which allows you to control the quartz jobs you have set up in the service.

But, like I said, this is just a very basic example.

With Quartz.NET you have the flexibility to set up 3 different job stores (list of job configurations with triggers and parameters you want to be run) namely:

1. In Code
2. Xml File
3. Database

In Quartz.NET you can clearly define exactly when you would like your jobs to be scheduled, from the simplest of triggers to the most complex facilitating built in simple triggers, calendars and cron expressions (handy site to create cron expressions). You can specify if the job should be set to recover (re-run) in the event of an unexpected error along with other job attributes.

Service Code Snippet:

var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient";

// set thread pool info
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";

// set remoting expoter
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";

var schedulerFactory = new StdSchedulerFactory(properties);
_scheduler = schedulerFactory.GetScheduler();

var jobDetail = new JobDetail("myJob", typeof(HelloWorldJob));
var trigger = TriggerUtils.MakeSecondlyTrigger("myTrigger");
_scheduler.ScheduleJob(jobDetail, trigger);
_scheduler.Start();

MVC Crystal Quartz Snippet:

<a style="font-size: 2em;" href="/CrystalQuartzPanel.axd">CrystalQuartz Panel</a>

Interface:


Windows service installation:

The windows service can be installed with installutil typically found in C:\Windows\Microsoft.NET\Framework\v2.0.50727 as follows.

1. Run the command prompt as administrator.
2. "cd" to where your built console application exists.
3. installutil QuartzSample.exe to install the service.

Afterthe service is installed, you can just run the MVC application to check out the crystal quartz panel.


This was just a quick overview of Quartz.NET, but from my own experience I’ve found Quartz.NET to be very easy to use, reliable and robust.

I hope this has post has at least wet your appetite to check out Quartz.NET in more detail.

Till next time..


Quartz Sample

No comments:

Post a Comment