How to use properties

About properties

Properties provide configuration mechanism for the routes definitions. The properties are identified by their names and accessed with the following format {{propertyName}}.

Simple

Each property can be a plain value or a password (value is hidden). The value of a property can be defined or not set, the latter case allows to prepare an application without defining initial values.

By default, password properties are not encrypted when they are stored. They are just hidden in the interface.

For information about how to encrypt password properties, see How to encrypt data integration password-type properties?.

Not Set

The value of a property can be defined or not set. Setting a value to Not Set allows preparing an application without defining initial values.

The application can be exported from a technical cluster A, then imported into another technical cluster B without actual values. In case the application already exists on technical cluster B and is actually updated, the properties values set on technical cluster B are not overridden during the import. For more information about technical clusters, see Types of technical clusters.

A route that contains a property with a value set to Not Set will not start.

From environment variable

The value of a property can also be extracted from an environment variable. You typically use this kind of properties in Active/Passive scenarios where the exact same application is replicated onto multiple servers, but where different servers must react differently.

The user that is used to start the cluster must be able to access the environment variable.

As an example, if an application is configured to send an email when some attribute value changes, if it possible to use the COMPUTERNAME environment variable on Windows servers to embed the name of the server into the mail subject or body.

A route that contains a property referencing an environment variable that is not set will not start.

As it is not possible to change the value of an environment variable once a process has started, it is not possible to change the value of such a property while a technical cluster is running.

As a consequence, restart the technical cluster to change the value of this kind of property.


From platform property

The value of a property can also be extracted from the conf/platform.properties file. You should use this kind of properties when you need to configure an application without any access to the graphical user interface.

A route that contains a property referencing a key that is not present in the conf/platform.properties file will not start.

It is not possible to change the value of such a property while a technical cluster is running. Any change performed to the conf/platform.properties file is not taken into account until the technical cluster has restarted.

As a consequence, restart the technical cluster to change the value of this kind of property.

Examples

Simple property in routes

In this example, we are trying to inject CSV files that are stored in a special folder. We want to define the path of the folder in a property in order to be able to change it easily. The routes need to be restarted in order to take the property changes into account.

See below the configuration of the properties

Here is the routes definition to use:

AbsorbCSV
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <!-- Monitor the proper import folder -->
        <from uri="file:{{ImportFolder}}"/>
        <!-- Parse and absorb -->
        <unmarshal>
            <csv/>
        </unmarshal>
        <split>
            <simple>${body}</simple>
            <to uri="tnd-absorption:AbsorbCSV"/>
        </split>
    </route>
</routes>

Platform property in routes

In this example, we are trying to send a mail using a mail server configured in the platform.properties file.

To start, we need to add a line into the conf/platform.properties file with the mail server hostname while the technical cluster is stopped.

conf/platform.properties
[...]
 
# Custom properties for data integration
org.acme.mailserver=mail.datacenter1.acme.int

We can then start the technical cluster and add a new data integration property to reference this property.

Finally, we can use this property in a route:

SendMail
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="timer:foo?repeatCount=1"/>
        <log message="Sending mail using server {{MAIL_SERVER}}"/>
    </route>
</routes>

Starting the routes will output the following in the logs:

Sending mail using server mail.datacenter1.acme.int

Simple and environment variable property in connector

In this example, we will display a welcome message in the log using a template defined in a data integration property and using an environment variable.

Hi <name>! Your cluster is running on <server name>

The name will come from the body of the route, the template and name of the server will come from data integration properties

The first thing to do is to create a simple connector. You can compile and package the following class, or directly download it: say-hello.jar

SayHello.java
package org.acme;

public class SayHello {

    private String template = "name=%s / server=%s";
    private String serverName = "<unknown>";

    public String sayHello(String name) {
        return String.format(template, name, serverName);
    }

    public String getTemplate() {
        return template;
    }

    public void setTemplate(String template) {
        this.template = template;
    }

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }
}

We will then define data integration properties for the template and to retrieve the name of the current server.

On Windows system, the environment variable to use is COMPUTERNAME.

On Linux, the environment variable to use is usually hostname. If it is not defined, you must export it so that the process of the technical cluster has access to it.

We can then create a library and a connector

 

When the following route is executed...

SayHello
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="timer:foo?repeatCount=1"/>
        <setBody>
            <constant>John Smith</constant>
        </setBody>
        <bean ref="sayHelloBean"/>
        <log message="${body}"/>
    </route>
</routes>

...it prints a nice welcome message in the log:

Hi John Smith. Your cluster is running on PC-RD80.



Related Links