Itération 122442
Itération 122442

Reputation: 2962

Implement a counter as a flowfile atribute in Nifi

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

So far, I have the following flow:

current 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

Answers (2)

notNull
notNull

Reputation: 31470

UpdateCounter processor updates counter and used only for monitoring feature, we can't access them using expression language.

  • To check counter value click on Top right corner hamburger menu > counters

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

Lamanus
Lamanus

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

Related Questions