Using Quartz to Trigger a Service

June 29 2009

2 comments
motif

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.)


We'd love to hear your opinion on this post


2 Responses to “Using Quartz to Trigger a Service”

  1. I’ve tried this example but a problem I have is that in my component I need to dependency inject a DAO and this doesn’t work because Quartz is instantiating the object. Is there a way to use Autowire an object when using the quarts transport?

  2. Your Example doesnt work.

    SAXParseException: cvc-complex-type.3.2.2: Attribute ‘queueEvents’ is not allowed to appear in element ‘vm:connector’.

    It gives same error even when we use 2.2 xsd