Configuration model for “Environment Aware” Routes
This document will describe a configuration mechanism for
Fuse routes that will simplify deployment. No longer will you need to prompt
installer for environment, and update properties in the install script. Instead,
the configuration file (.cfg) contains property values for every environment. The route only reads
the properties associated with the environment in which the route runs. This
configuration model brings with it the following unique characteristics:
- Properties file contains values of ALL properties for ALL environments.
- Deployment no longer needs to involve logic to set environment-specific property values.
By limiting the logic and user interaction of the deployment
script, there is less chance of making an error in the script. Also, there is a
reduction in (scripting) code that must be maintained. Environment specific
values are no longer hard-coded into the script, rather these properties have
been set up-front in static configuration (.cfg) file(s) that gets deployed
with the route(s).
Version Info
This document was written based on JBoss Fuse 6.x and applies
to bundles running inside this version of the JBoss Fuse container.
Sample Property file
Let’s take a look at how a property file (.cfg) will look
using this model. Notice the file contains properties for every environment
(DEV, VAL, INT, PRD, etc.). Each property contains a special identifying prefix
to distinguish it as belonging to a specific environment.
The above properties are written in such a way that they are
“environment aware” and only the property for the environment Fuse is running
in is picked up. The rest of the properties are ignored. Having all properties
for all environments may seem excessive, however it could be argued that having
property values for every environment available in the configuration file as a
reference is useful.
How does Fuse know what environment it is running in?
Fuse will need to be configured to “know” what environment
it is running in. You will need to do a
one-time manual edit of a specific Fuse configuration file.
Inside the Fuse configuration file
‘$FUSE_INSTALL\etc\system.propeties’ you can add the following entries.
The two added entries are ‘karaf.environment’ and
‘karaf.instance’ (lines 37 and 38.) Of course, the values of these new system
properties should be appropriate for your environment and instance. You may
only have a single machine per-environment, in that case, ‘karaf.environment’ is
the only system property that needs to be defined. Add ‘karaf.instance’ if a environments have 2
or more machines, and property values may differ depending on the particular machine
(instance) within a given environment. You will need to restart Fuse in order
for these environment indicator properties to be available to your bundle’s
configuration.
Once
Fuse is restarted with the above system properties set, the following entries
added to your bundle’s configuration file will now have special meaning (see
lines 3 and 4 below).
The configuration file specifies the values of properties by
using nested system properties to identify the environment. For example line 3
above the value of ‘to.uri’ is defined by using a nested system property
‘karaf.environment.’
${DEV.to.uri}
The
‘${karaf.environment}’ system property (defined in the Fuse ‘system.properties’
file) will resolve at runtime to the environment name e.g. ‘DEV’, and then that
is used to designate the prefix for the property i.e. ‘${DEV.to.uri}’. This
then resolves to the correct configuration property found further down in the
configuration file (see line 7 in snippet from configuration file.) In this
example, the true value of ‘to.uri’ becomes the value of the ‘DEV’-prefixed
version of this property.
Properties for all environments where the route will be
installed will be included in the configuration file. The correct prefix for
each environment will match 'karaf.environment' used for the environment and
should be specified exactly as it appears in the ‘system.properties’ file of
the container in which it appears.) For example: DEV, VAL, INT, PROD, etc.
Using the properties in the Camel Context (Spring XML
configuration)
Because the use of the nested properties is confined to the
configuration file only, there is nothing special that needs to be done in the
Spring configuration for your route in order to use this configuration model.
The spring configuration will refer to the normal
(non-prefixed) version of the properties. The environment-specific resolution
is confined to the property file, and
does not need to be a concern within the Spring XML of your route.
See lines 27-31 where property placeholders are used as
values of properties injected into a Spring bean. See line 37 where the value
of a property placeholder is used within the camel route. (Notice the need for double
brackets ‘{{‘ and ‘}}’ to de-reference such properties from within the camel
route. )
In summary, the use of env-specific properties within your
configuration will not affect your route’s code.
No comments:
Post a Comment