Reputation: 2962
Using Nifi, I want to handle errors of a processor.
If the processor sends the flowfile to the failure link, I want to send it back x times to the processor that failed to process it.
For that, I wanted to implement a counter in the flowfiles attributes. However, I am facing two issues
counter
attribute ?counter
attribute if it exists ?So far, I have the following flow:
And I am stuck on the "Update Counter" processor. I do not understand how I can achieve this.
The attribute counter
does not exist when the flowfile first comes in. I want to check if it exists, if not, ad it to the flow file. When it comes later during execution, if it exists, I want to increment it. How is that possible ?
Upvotes: 2
Views: 8383
Reputation: 31470
UpdateCounter processor updates counter and used only for monitoring feature, we can't access them using expression language.
How to check or add to flowfile?
Use UpdateAttribute
processor and add new property called:
counter
${counter:isNull():not():ifElse('${counter:plus(1)}','${literal("0")}')}
With the above expression we are checking is the counter attribute notnull
True then incrementing the attribute value by 1.
False adding the attribute counter
with value as 0
Take a look into this thread regards to similar usecase and you can also use updateattribute processor storing the state locally option too.
Upvotes: 2
Reputation: 13541
Use this expression.
${counter:replaceNull(0):plus(1)}
If the counter
attribute does not exist, this will create the value with 1
and if the counter
attribute exist, it will be updated +1.
Upvotes: 6