The Java QUARTZ Job Scheduler framework is a common piece of software and can be found in many environments. Although the Mulesoft Anypoint Platform provides its own scheduling API, it is a common task to use the QUARTZ framework instead. Especially, if scheduling might be centralized among different applications and might not only be used for the Mule ESB.
Luckily, you can use the QUARTZ Connector in the Anypoint Studio if you come across such use cases.
In combination with the Spring support inside Mule, you can achieve a very flexible and powerful combination to run different QUARTZ jobs even in a clustered environment. In the following, you can find a short outline how such a setting can be achieved.
Spring Bean Definitions
First of all, make sure that all required libraries are in your classpath. Dragging a QUARTZ component into your canvas and creating a flow should actually be enough as Anypoint Studio should add all dependencies automatically to your project.
Afterwards, you have to ask yourself where the configuration of the QUARTZ scheduler comes from. As I mentioned before, we use Spring for the configuration. To do this, we need a spring:beans section in one of the mule-config XML-Files as shown in the example bellow:
... AUTO ... .. org.quartz.impl.jdbcjobstore.JobStoreTX ... QRTZ_ ... ...
spring:beans tells Mule that inside of the tags Spring beans are defined. The quartzSchedulerFactory is the first bean we initialize. It is of the type org.springframework.scheduling.quartz.SchedulerFactoryBean. Via XML we simply add our QUARTZ configuration via a spring property definition.
As we want to use these configuration in a clustered environment and we want to prohibit, that jobs are executed more than once we use the JobStoreTX. However, as a side effect, we need a database connection to synchronize different nodes. Therefore, we have to define a datasource to tell QUARTZ about the jobs’ configuration and synchronization. This is done with the quartzDataSource bean with the help of a com.zaxxer.hikari.HikariDataSource class.
QUARTZ Connector Config
With such a configuration you can easily realize scheduled jobs inside sthe Anypoint Platform which is connected to your existing QUARTZ environment. Of course you have to change some of the settings above according to your environment.