ServiceMix Quartz

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

Maven Archetype

You can use Maven servicemix-quartz-service-unit archetype to create a Quartz service unit:

mvn archetype:create \
  -DarchetypeGroupId=org.apache.servicemix.tooling \
  -DarchetypeArtifactId=servicemix-quartz-service-unit \
  -DarchetypeVersion=2010.01 \
  -DgroupId=your.group.id \
  -DartifactId=your.artifact.id \
  -Dversion=your-service

Endpoint Configuration

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

Quartz Cron Trigger Endpoint
<quartz:endpoint service="test:service" endpoint="endpoint1" targetService="test:receiver1">
  <quartz:trigger>
    <quartz:cron cronExpression="0/5 * * * * ?" />
  </quartz:trigger>
</quartz:endpoint>
Quartz 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>
Quartz 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"))); 
    }
}
  • No labels