Contents


Loading IBM Integration Bus configuration data from a file using the FileRead node and shared variables

Comments

Why load configuration data into memory?

In some application scenarios, it is better to use a configuration file with static data and load it into memory only once, when the flow starts, instead of loading it before every flow execution. For example:

  • When you want to use an external file to control the sequence in which applications and message flows are invoked
  • When you want to store static, environment-specific information outside of IBM Integration Bus, so it can be managed by people with limited product and application knowledge.
  • When you want to control log levels and log file names through a configuration file
  • When you want to store multi-language statements and error messages in an external file

In the above scenarios, keeping the configuration files outside IBM Integration Bus frees you from editing the message flow whenever there is a change to the data. Also, reading a configuration file during every run of a message flow is time-consuming, and loading them into memory once means fewer I/O operations, faster data access, and better performance.

Design

  • The FileRead Node is used to read the configuration file from within a message flow.
  • Use shared variables to load configuration data to an in-memory cache in the message flow. The configuration data is loaded when the first message passes through the flow after each broker startup. Shared variables are long-lasting and can persist during the lifetime of the execution group process, the lifetime of the flow or node, or the lifetime of the SQL node that declares the variable, whichever is the shortest.
  • You can use shared variables anywhere in the scope of the message flow to access the in-memory data. They are visible to all messages passing through the flow. Whenever there is a change to the configuration data, you can edit the configuration file and restart the message flow to implement the change.

Sample implementation

Here is an example that involves storing web service credentials in a configuration file, loading it into memory during the first run of the message flow, and then accessing it during all subsequent transactions in the message flow. The configuration file name is credentials.properties, and it contains the Username admin and the Password adminpwd. You use the FileRead Node to read the configuration data:

  1. Create a DFDL to define the structure of the configuration file: Select File => New => Message Model, select Record-oriented text as the Format, and click Next.
  2. Select Create a DFDL schema file using this wizard to guide you and then click Next. Enter the DFDL schema file name and message name: Figure 2
    Figure 2
  3. Click Next and enter 2 for Number of body fields. Uncheck The first record is a header and The last record is a trailer. Click Finish: Figure 3
    Figure 3
  4. In the DFDL created, edit the field names as shown below: Figure 4
    Figure 4
  5. Edit the Separator property of sequence under the Representation property to =: Figure 5
    Figure 5
  6. Here is the message flow demonstrating the loading of configuration data into memory: Figure 6
    Figure 6

BuildRequest

From the BuildRequest node before propagating to the FileRead node(out2), a check is performed to see if the configuration shared variable is loaded. If he shared variable is not available, then the file read is triggered. Usually, loading the configuration data to shared variables is performed only during the first run of the flow. Here is some sample code to trigger the loading of configuration data into memory:

Figure 7
Figure 7

FileRead Node

In the FileRead node, configure the Input directory from where the file needs to be read and the File name, as shown below:

Figure 8
Figure 8

For Message domain, select DFDL and then select the message model:

Figure 9
Figure 9

LoadToMemory

Using the following code, load the data read from the file into a shared variable:

Figure 10
Figure 10

Control then goes back to the BuildRequest Node:

BuildRequest

It executes the code below to set the credentials in the request:

Figure 11
Figure 11

Conclusion

The article explained the advantages of loading IBM Integration Bus configuration files into memory, and showed you how to do it during the first executions of a message flow.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Middleware
ArticleID=958672
ArticleTitle=Loading IBM Integration Bus configuration data from a file using the FileRead node and shared variables
publish-date=12272013