How to configure projects to use external resource files

How to configure projects to use external resource files

book

Article ID: KB0070972

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10.6 and later

Description

In some cases, your project may need to use resource files that cannot be kept in the project's default resources location (src/main/resources/). Follow the guidance below on how to use the epadmin 'deploydirectories' option to load external resource files.

Resolution

Let's use the CSV File Reader adapter as an example. This is an adapter which reads a csv file as a resource.

By default, the Streaming runtime will look for resource files under the fragment project's src/main/resources/ folder. However, it may be required to load these files from different locations, depending on the environment in which the application is being deployed. In that case, you may use the epadmin 'deploydirectories' option, as noted in the Help under Home > EP Commands > epadmin and epdev References > epadmin-node > (sub-heading) epadmin install node > (sub-heading) install Command Parameters.

First, create a Parameter in your EventFlow module to represent the CSV filename:

set CSV file name parameter

Here, we are setting the default value to 'file1.csv', which exists in the project's src/main/resources/ directory. This step is only needed so that the platform will successfully typecheck your application when working in Studio. This value will be overridden using a substitution variable later.

Next, set the CSV File Reader's 'File Name' property using the parameter ('csv_file') that you just created:

set CSV file name

Next, create an EventFlow Deployment HOCON configuration to override the default value of the 'csv_file' parameter. Here, we use a substitution variable 'CSV_FILE':
 
 EventFlowDeployment = {   containers = {     "A" = {       moduleName = "com.tibco.sb.sample.adapter.csvreader.csvreader-sample.sbapp"       containerParameterSettings = {         parameters = {           "csv_file" = "${CSV_FILE:-file1.csv}"             }           }         }       } }

Here, we're using the substitution variable 'CSV_FILE' to set the value for the 'csv_file' parameter. Again, a default value of 'file1.csv' is used to prevent any errors during Studio typecheck.

You may now run your EventFlow Fragment in Studio. In the Run Configuration under the 'Node' tab, specify the location to a different csv file. For example, C:/resources/:

deploydirectories used in Run Config

Finally, assign a non-default value for the CSV_FILE substitution variable. Do this in your Run Configuration under the 'Parameters' tab:

using substitution var in run config

This will ensure that 'file3.csv', located on the system under C:/resources/, will be loaded by the CSV File Reader. This is one example of how to configure projects to use external resource files.  
 

Issue/Introduction

This article describes how to configure Streaming projects to use external resource files (i.e. resource files that cannot be kept in the project's src/main/resources/ directory).