servicemix-quartz

The servicemix-quartz component is a standard JBI Service Engine able to schedule and trigger jobs using the great Quartz scheduler.

Using servicemix-quartz as a standard JBI component

Installation

Installing the servicemix-quartz component can be done in several ways:

  • drop the installer zip in an hotdeploy directory monitored by ServiceMix
  • using ant tasks

Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.

To configure the internal Quartz Component (eg cluster, database, plugin), put quartz.properties into SERVICEMIX_HOME
/conf (Root classpath)

Service Unit packaging

A service unit will typically consist in:

  • an xbean.xml configuration file

Content of xbean.xml file to be packaged as a SU

<beans xmlns:quartz="http://servicemix.apache.org/quartz/1.0">

  ... add endpoints here ...

</beans>

Using servicemix-quartz in a ServiceMix xml configuration file

<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
       xmlns:quartz="http://servicemix.apache.org/quartz/1.0">

  <sm:container ...>
    <sm:activationSpecs>
      <sm:activationSpec>
        <sm:component>
          <quartz:component>
            <quartz:endpoints>

              ... add quartz endpoints here ...

            </quartz:endpoints>
          </quartz:component>
        </sm:component>
      </sm:activationSpec>
      ...
    </sm:activationSpecs>
  </sm:container>
  ...

</beans>

Quartz endpoint

The quartz endpoint can be used to fire message exchanges at a given (recurrent) time.

Examples:

Cron trigger endpoint
<quartz:endpoint service="test:service" endpoint="endpoint1" targetService="test:receiver1">
  <quartz:trigger>
    <quartz:cron cronExpression="0/5 * * * * ?" />
  </quartz:trigger>
</quartz:endpoint>
Simple trigger endpoint
<quartz:endpoint service="test:service" endpoint="endpoint2" targetService="test:receiver2">
  <quartz:trigger>
    <quartz:simple repeatCount="0" repeatInterval="1000" />
  </quartz:trigger>
</quartz:endpoint>
Custom marshaler
<quartz:endpoint service="test:service" endpoint="endpoint3" targetService="test:receiver3">
  <quartz:jobDetail>
    <quartz:jobDetail>
      <quartz:jobDataAsMap>
        <quartz:property key="xml"><![CDATA[
          <hello>world</hello>
        ]]></quartz:property>
      </quartz:jobDataAsMap>
    </quartz:jobDetail>
  </quartz:jobDetail>
  <quartz:triggers>
    <quartz:simple repeatCount="0" repeatInterval="1000" />
    <quartz:cron cronExpression="0 * 1 * * ?" />
  </quartz:triggers>
  <quartz:marshaler>
    <bean class="org.apache.servicemix.quartz.CustomMarshaler" />
  </quartz:marshaler>
</quartz:endpoint>

The snippet above requires a CustomMarshaler implementation that can get the information from the job data map and add it to the NormalizedMessage.

Custom marshaler class
public class CustomMarshaler extends DefaultQuartzMarshaler {

    public void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context)
                                                               throws JobExecutionException, MessagingException {
        super.populateNormalizedMessage(message, context);
        //add your own content to the message here
        message.setContent(new StringSource((String) context.getJobDetail().getJobDataMap().get("xml"))); 
    }
}