Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • lookup or creating endpoints
  • lookup of beans in the Registry
  • additional supported in Spring XML (see below in examples)
  • using Blueprint PropertyPlaceholder with Camel Properties component
  • using @PropertyInject to inject a property in a POJO
  • Camel 2.14.1 Using default value if a property does not exists
  • Camel 2.14.1 Include out of the box functions, to lookup property values from OS environment variables, JVM system properties, or the service idiom.
  • Camel 2.14.1 Using custom functions, which can be plugged into the property component.

...

Code Block
    @PropertyInject(value = "myTimeout", defaultValue = "5000")
    private int timeout;

Using out of the box functions

Available as of Camel 2.14.1

The Properties component includes the following functions out of the box

  • env - A function to lookup the property from OS environment variables
  • sys - A function to lookup the property from Java JVM system properties
  • service - A function to lookup the property from OS environment variables using the service naming idiom

As you can see these functions is intended to make it easy to lookup values from the environment. As they are provided out of the box, they can easily be used as shown below:

Code Block
  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
    <route>
      <from uri="direct:start"/>
      <to uri="{{env:SOMENAME}}"/>
      <to uri="{{sys:MyJvmPropertyName}}"/>
    </route>
  </camelContext>

You can use default values as well, so if the property does not exists, you can define a default value as shown below, where the default value is a log:foo and log:bar value.

Code Block
  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
    <route>
      <from uri="direct:start"/>
      <to uri="{{env:SOMENAME:log:foo}}"/>
      <to uri="{{sys:MyJvmPropertyName:log:bar}}"/>
    </route>
  </camelContext>

 

The service function is for looking up a service which is defined using OS environment variables using the service naming idiom, to refer to a service location using hostname : port

  • NAME_SERVICE_HOST
  • NAME_SERVICE_PORT

in other words the service uses _SERVICE_HOST and _SERVICE_PORT as prefix. So if the service is named FOO, then the OS environment variables should be set as

Code Block
export $FOO_SERVICE_HOST=myserver
export $FOO_SERVICE_PORT=8888

 

For example if the FOO service a remote HTTP service, then we can refer to the service in the Camel endpoint uri, and use the HTTP component to make the HTTP call:

Code Block
  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
    <route>
      <from uri="direct:start"/>
      <to uri="http://{{service:FOO}}/myapp"/>
    </route>
  </camelContext>

 

And we can use default values if the service has not been defined, for example to call a service on localhost, maybe for unit testing etc

Code Block
  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
    <route>
      <from uri="direct:start"/>
      <to uri="http://{{service:FOO:localhost:8080}}/myapp"/>
    </route>
  </camelContext>

Using custom functions

Available as of Camel 2.14.1

...