In this series of blogs, we attempt to explain and show how to use Quartz to schedule both inbound and outbound jobs, and how to enable Mule Quartz connector so we can use Quartz manager to monitor jobs.
For Mule's reference, "The Quartz transport provides support for scheduling events and for triggering new events. An inbound quartz endpoint can be used to trigger inbound events that can be repeated, such as every second. Outbound quartz endpoints can be used to schedule an existing event to fire at a later date. Users can create schedules using cron expressions, and events can be persisted in a database."
An inbound quartz endpoint is used when we need to trigger inbound events periodically, like generating a predefined message, or loading a file, and then pass the generated message down the flow, either directly or through a VM or JMS.
An outbound quartz endpoint is used when we need to trigger an event based on incoming events. For example, in our world, we want to send all users a 25% off coupon everyday at 9am, for all the users who click on the welcome link embedded in our email campaign for the previous day.
The key difference between the inbound and outbound endpoint is that inbound message is scheduled entirely by Quartz, while the outbound endpoint is scheduled by Quartz, but only after an incoming event has been triggered. We will use some examples to illustrate the key differences.
Quartz Connector
But before we dive into the nitty gritty details, we need to create a Mule Quartz connector first. A Mule Quartz connector is how a Quartz schedule should be created by Mule.Here is a sample scheduler using RAMJobStore. Enter the following block of xml in Mule flow's configuration XML section.
<quartz:connector name="quartzConnector_vm" validateConnections="true" doc:name="Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="MuleScheduler1"/>
<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:factory-property key="org.quartz.jobStore.class" value="org.quartz.simpl.RAMJobStore"/>
</quartz:connector>
Mule uses "quartz:factory-property" to specify all Quartz related properties.
Here is how to configure a clustered scheduler using a JDBCJobStore using MySQL. Enter the following block of xml in Mule flow's configuration XML section.
<quartz:connector name="quartzConnector_vm"
validateConnections="true" doc:name="Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName"
value="JmxScheduler" />
<quartz:factory-property key="org.quartz.scheduler.instanceId"
value="_CLUSTERED" />
<quartz:factory-property key="org.quartz.jobStore.isClustered" value="true" />
<quartz:factory-property key="org.quartz.scheduler.jobFactory.class"
value="org.quartz.simpl.SimpleJobFactory" />
<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" />
<!-- JDBC JOB STORE -->
<quartz:factory-property key="org.quartz.jobStore.class"
value="org.quartz.impl.jdbcjobstore.JobStoreTX" />
<quartz:factory-property key="org.quartz.jobStore.driverDelegateClass"
value="org.quartz.impl.jdbcjobstore.StdJDBCDelegate" />
<quartz:factory-property key="org.quartz.jobStore.dataSource"
value="quartzDataSource" />
<quartz:factory-property key="org.quartz.jobStore.tablePrefix"
value="QRTZ_" />
<!-- MYSQL Data Source -->
<quartz:factory-property
key="org.quartz.dataSource.quartzDataSource.driver" value="com.mysql.jdbc.Driver" />
<quartz:factory-property key="org.quartz.dataSource.quartzDataSource.URL"
value="jdbc:mysql://localhost:3306/quartz2" />
<quartz:factory-property key="org.quartz.dataSource.quartzDataSource.user"
value="root" />
<quartz:factory-property
key="org.quartz.dataSource.quartzDataSource.password" value="root" />
<quartz:factory-property
key="org.quartz.dataSource.quartzDataSource.maxConnections" value="8" />
<!-- JMX Enable -->
<quartz:factory-property key="org.quartz.scheduler.jmx.export"
value="true" />
<quartz:factory-property key="org.quartz.scheduler.jmx.objectName"
value="quartz:type=QuartzScheduler,name=JmxScheduler,instanceId=NONE_CLUSTERED" />
</quartz:connector>
To verify that the Quartz connector has been configured successfully, go the "Global Elements" in the Mule flow.
Click on Quartz.
Click on "Properties" tab,
Verify all Quartz properties have been properly configured.
Use Inbound Quartz End Point
An inbound quartz end point is self-triggered and will generate one or more messages, whose payload can be preconfigured or reloaded from a file.
Here is the picture of the sample Mule Flow. Every 5 seconds, Quartz end point will generate a VM message containing "HELLO!' as its body. We have a Java transform that listens to the same VM end point and processes the generated "HELLO!" message.
Now we need to select our already defined quartz connector by clicking on the "References" tag on the Quartz component and select the appropriate pre-defined quartz connector from the drop down list for "Connector Reference:" field.
We will discuss Quartz outbound events in the next blog.
the blog is good and Interactive it is about Mulesoft it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online training
ReplyDeleteThank you for sharing such a great information.Its really nice and informative.hope more posts from you. I also want to share some information recently i have gone through and i had find the one of the best mulesoft videos
ReplyDeleteThanks for sharing valuable information and very nice blog. Keep posting.
ReplyDeletemulesoft certification
mulesoft training in hyderabad
Thanks for sharing such a nice info. I hope you will share more information
ReplyDeleteMulesoft Online Course
Mulesoft Online Training india
mmorpg oyunları
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
Tiktok jeton hilesi
saç ekim antalya
referans kimliği nedir
instagram takipçi satın al
Metin pvp
Metin2 pvp serverlar
perde modelleri
ReplyDeletesms onay
Türk Telekom Mobil Ödeme Bozdurma
NFT NASİL ALINIR
ankara evden eve nakliyat
trafik sigortası
dedektör
web sitesi kurma
aşk kitapları