Fork me on GitHub

Camel Repository Scheduler Job Component

A default Repository Scheduler Job implementation is provided by org.onehippo.forge.camel.scheduling.DefaultCamelRepositoryJob. This implementation makes it easier to create a Hippo Repository Scheduler based task.

This job implementation simply reads the following attributes from org.onehippo.repository.scheduling.RepositoryJobExecutionContext, find a CamelContext and invokes #sendBody(String endpointUri, Object body);.

The CamelContext is determined by the camel.context.id attribute value. If, however, the attribute value is blank, then the first found CamelContext is used by default. The endpointUri is determined by the camel.endpoint.uri attribute value, and the body is set to the org.onehippo.repository.scheduling.RepositoryJobExecutionContext instance.

If you want to configure a Camel Repository Scheduler Job Component to invoke an endpoint URI like 'direct:processCamelRepositoryJob' for instance, then you can configure the following repository job configuration under /hippo:configuration/hippo:modules/scheduler/hippo:moduleconfig in the repository (in the following example, it is assumed that you configure this job under a new job group named 'camel-demo'):

<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="camel-demo" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>hipposched:jobgroup</sv:value>
  </sv:property>
  <sv:node sv:name="ExampleSimpleCamelJob">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
      <sv:value>hipposched:repositoryjob</sv:value>
    </sv:property>
    <sv:property sv:multiple="true" sv:name="hipposched:attributeNames" sv:type="String">
      <sv:value>camel.endpoint.uri</sv:value>
      <sv:value>camel.context.id</sv:value>
    </sv:property>
    <sv:property sv:multiple="true" sv:name="hipposched:attributeValues" sv:type="String">
      <sv:value>direct:processCamelRepositoryJob</sv:value>
      <sv:value/>
    </sv:property>
    <sv:property sv:name="hipposched:repositoryJobClass" sv:type="String">
      <sv:value>org.onehippo.forge.camel.scheduling.DefaultCamelRepositoryJob</sv:value>
    </sv:property>
    <sv:node sv:name="hipposched:triggers">
      <sv:property sv:name="jcr:primaryType" sv:type="Name">
        <sv:value>hipposched:triggers</sv:value>
      </sv:property>
      <sv:node sv:name="ExampleSimpleCamelJobTrigger">
        <sv:property sv:name="jcr:primaryType" sv:type="Name">
          <sv:value>hipposched:crontrigger</sv:value>
        </sv:property>
        <sv:property sv:multiple="true" sv:name="jcr:mixinTypes" sv:type="Name">
          <sv:value>mix:lockable</sv:value>
        </sv:property>
        <sv:property sv:name="jcr:uuid" sv:type="String">
          <sv:value>48f45526-542c-482b-b17e-b20bdc210ca6</sv:value>
        </sv:property>
        <sv:property sv:name="hipposched:cronExpression" sv:type="String">
          <sv:value>0 * * * * ?</sv:value>
        </sv:property>
        <sv:property sv:name="hipposched:nextFireTime" sv:type="Date">
          <sv:value>2015-03-23T15:35:00.000-04:00</sv:value>
        </sv:property>
      </sv:node>
    </sv:node>
  </sv:node>
</sv:node>
      

So, if the Camel route is defined like the following example, then whenever the scheduler job is invoked, it will simple leave a log with the body object:

  <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">

    <!-- SNIP -->

    <route>
      <from uri="direct:processCamelRepositoryJob" />
      <!-- Leave log. -->
      <to uri="log:org.onehippo.forge.camel.demo?level=INFO"/>
    </route>

    <!-- SNIP -->

  </camelContext>