using custom properties in Nifi

Viewed 1466

How would I use one custom property within another in Nifi? Please note that am using custom property file.

Eg: I have the following in the custom property file.

prop_1=/path/to/dir1
prop_2=/path/to/dir2
prop_3=${prop_1}/${prop_2}/file1
prop_4=${prop_1}/${prop_2}/file2

Now, within nifi processor, where expression language is supported, when I give

${prop_3} or ${prop_4}

I get error ${prop_1} is not a file or directory.

But if I provide the value as ${prop_1}/${prop_2}/file1, it works.

What is the problem when I give ${prop_3}?

Thanks,

John

2 Answers

Properties file is loaded as a map of key-value constants. No evaluations are done during this load.

You defined prop_3=${prop_1}/${prop_2}/file1. This means, that prop_3 equals to literal value ${prop_1}/${prop_2}/file1 (N.B.: no evaluations).

So, in attribute (that supports expression language) you set: ${prop_3}. And NiFi evaluated the ${prop_3} expression to literal value ${prop_1}/${prop_2}/file1 (again, without repeated evaluation).

As daggett noted, the property values are loaded from the custom properties file in a single operation, and cannot reference each other during that load process. However, you can use an UpdateAttribute processor before the processor which is doing this evaluation, and use a dynamic property (click the + button on the top right of the properties table) to assign prop3 = /${prop1}/${prop2}/file1 and then reference ${prop3} in any following processors.

Related