Reading the Camel aggregation completion timeout value from properties

Solution Unverified - Updated -

Environment

  • Fuse ESB 7.1.
  • JBoss Fuse 6.0

Issue

User wants to resolve the Camel aggregation completion [1] value from a properties file (from Karaf/ServiceMix/Fuse properties in particular). The motivation behind this request is to avoid hard coding completion timeout values in the code - as a result global change of timeout setting should be possible without redeployment of the given module.

[1] http://camel.apache.org/aggregator2.html

Resolution

Camel can read the timeout completion value dynamically from a properties file using the Camel Simple [1] expression.

Below you can find the example for Blueprint DSL:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:camel="http://camel.apache.org/schema/blueprint"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
  xmlns:prop="http://camel.apache.org/schema/placeholder"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd
    http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint">
    <cm:default-properties>
      <cm:property name="aggregationTimeout" value="100"/>
    </cm:default-properties>
  </cm:property-placeholder>
  ...
  <aggregate strategyRef="aggregatorStrategy">
    <correlationExpression>
      <constant>true</constant>
    </correlationExpression>
    <completionTimeout>
      <simple>${properties:aggregationTimeout}</simple>
    </completionTimeout>
    <to uri="mock:result"/>
  </aggregate>
  ...
</blueprint>

Starting from the version 2.10.5, 2.11.1 and 2.12.0 Camel also supports [2] attribute properties placeholders in Blueprint DSL attributes, as demonstrated at snippet below:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:camel="http://camel.apache.org/schema/blueprint"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
  xmlns:prop="http://camel.apache.org/schema/placeholder"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd
    http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint">
    <cm:default-properties>
      <cm:property name="aggregationTimeout" value="100"/>
    </cm:default-properties>
  </cm:property-placeholder>
  ...
  <aggregate strategyRef="aggregatorStrategy" prop:completionTimeout="aggregationTimeout">
  ...
</blueprint>

A Fix was implemented in ticket CAMEL-6351 [2] and has also been backported [3] to the Fuse 2.10.0-fuse-71-xx, 2.10.0-fuse-72-xx and 2.11.0-fuse-00-xx.

[1] http://camel.apache.org/simple
[2] https://issues.apache.org/jira/browse/CAMEL-6351
[3] https://issues.jboss.org/browse/MR-719

Diagnostic Steps

In order to see the working example see the zipped proof of concept (in the form of the Maven project) attached to this document.

Attachments

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.