Wednesday, October 28, 2015

Quartz Scheduler in Liferay

Today we will discuss about Schedular in Liferay. Sometime we have a situation in which we have to perform a task repeatedly after a certain period of time.Ex- Send a mail every week.

Liferay provide a simple way to achieve this.We create schedular class and provide entry of timing in liferay-portlet.xml. Time for schedular can be define by 3 ways:-

1)Using Liferay Feature

Ex-   <simple>

Here in time unit we mention minute and in simple trigger value we mention 1 .This means this job run in each minute.

2)Using Property file

Ex- <cron>
<property-key>everyThirtySecond </property-key>

We define key and cron expression in file like everyThirtySecond = 0/30 * * * * ?

3)Using Cron Expression Directly

Ex- <cron>
        <cron-trigger-value>0/15 * * * * ?</cron-trigger-value> 

This job runs in every 15 seconds.

Note:- For Cron Trigger Expression you may refer here.

So lets start this step by step:-

Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as schedular and click finish. After that Right Click on your project and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.

Step 2:-Create Schedulars
Inside com.test package create 3 classes that implements MessageListener inteface and provide the definition of receive method.

Step 3:-Provide timing in liferay-portlet.xml
Open liferay-portlet.xml and paste this:-

Here we provide the entries of all 3 Schedulars.

Step 4:-Create
Inside docroot/WEB-INF/src create and paste this:-

everyThirtySecond = 0/30 * * * * ?

because second schedular take value from property file.

Step 5:-Check output
Deploy the portlet and add to page:-

Now check eclipse console

Project Structure

Hope this will Help....

You can Download Source code from  Schedular in Liferay.

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!