In this article, we will look into scheduling service/job using Quartz Inbound component of Mule Studio
Introduction
Sometime we may need to schedule a service that will run at a certain period of time. This article will talk about that by using Quartz Endpoint component.
What we need to have for doing the experiment?
We need
- Download Mule ESB
- Everything should be up and running properly
Objective
We will write a simple message to a file after a certain interval of time.
Let us start the experiment
First create a Mule Project.Then create a Mule Quartz connector.For doing so, first go to the "Global Elements" tab.Click "Create" button and from the "Connectors", choose "Quartz" and click on "OK" button.

Next,in the "Quartz Global Elements Properties", come to the "Advanced" tab.In the "Factories" property section, click on the
button and enter the below Key/Values
Key |
Value |
org.quartz.scheduler.instanceName |
TestMuleScheduler |
org.quartz.threadPool.class |
org.quartz.simpl.SimpleThreadPool |
org.quartz.threadPool.threadCount |
3 |
org.quartz.scheduler.rmi.proxy |
false |
org.quartz.scheduler.rmi.export |
false |

So once the Mule Quartz connector is setup properly, now we will use a Inbound Quartz End Point.For doing so, first drag and drop a "Inbound Quartz" component from the "endpoint section of the palette on to the "Message flow".Double click on it to open up it's properties window.
In the "General" table" change the "Display Name" to "QuartzInbound".Give the "job Name" to "MyFirstQuartzScheduler" and "Repeat Interval" to "0 hours", "0 minutes" and "10 seconds" which indicates that our scheduler will trigger after every 10 seconds.

Now we need to add a new job. Click on plus sign.From teh "Select element to use" popup that appears, choose the "quartz:event-generator-job" and click "Next" button.

From the "Event Generator Job" screen,enter the values for "Group Name", "Job Group Name" as "TestScheduler" and for "Text" enter "This is a job scheduler that will write to file after every 10 seconds.".Once done, click "Finish" button.

Next come to the "References" tab of "Quartz(Inbound Endpoint)" screen and from "Connector Reference" choose the connector name which is "QuartzConnector" here.

Next choose a "File Outbound" Endpoint and configure it properly

The complete flow is as under
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<quartz:connector name="QuartzConnector" validateConnections="true" doc:name="Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="TestMuleScheduler"/>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="3"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
</quartz:connector>
<flow name="TestScheduleServiceFlow1" doc:name="TestScheduleServiceFlow1">
<quartz:inbound-endpoint jobName="MyFirstQuartzScheduler" repeatInterval="10000" responseTimeout="10000" connector-ref="QuartzConnector" doc:name="QuartzInbound">
<quartz:event-generator-job groupName="TestScheduler" jobGroupName="TestScheduler">
<quartz:payload>This is a job scheduler that will write to file after every 10 seconds.</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<file:outbound-endpoint path="C:\Users\niladri.biswas\Desktop\output" responseTimeout="10000" doc:name="Destination"/>
</flow>
</mule>
So we are almost done.As a last step, let us run the flow and we can see that the operation is happening at a time interval of 10 seconds

References
- Quartz Endpoint Reference
- Quartz Transport Reference
Conclusion
So this article has taught us as how to schedule service using Quartz component.Hope it will be helpful.Thanks for reading