Using Quartz to Trigger a Service

June 29 2009


When you’re working with Mule, you’re usually concerned about responding to messages that come in and making sure you’re routing them correctly from service to service. But what if you just want to trigger a service component on a set interval? What if its method doesn’t require any incoming data at all?

You can use the Quartz transport to trigger a service component method at scheduled intervals. In this example, the service component has a single method that doesn’t take any parameters, so we don’t need to pass any data to it. We’ll use the EventGeneratorJob, which automatically generates a message. By not specifying a ‘payload’ element on this job, there is no data to try to match to the service method, so Mule will match the method with no arguments.

The Service Component

This is our service component class implementation. Note that it has a single method, which does not accept any parameters.

Configuring the Service

In the Mule configuration file, you configure the following elements for the service:

  • A Quartz inbound endpoint that specifies the job that will trigger the message and how often to run the job.
  • The service component class containing the method you want to fire.
  • A VM outbound endpoint that specifies where to send the results from the service component’s method.

Running the Example

The following test case, available in the Mule test suite, runs the above configuration and checks the results.

For more information on the Quartz transport and the Event Generator job, see the Quartz Transport page in the Mule User’s Guide. (Login is required, but registration is free and only takes a moment.)