James Jithin
James Jithin

Reputation: 10565

How to use value of a counter in NiFi

In NiFi 1.3.0, I have created a flow to split a JSON file and update the counter with name filenamecounter so that I can save each split into different file names. I see that the counter value gets updated when I view the NiFi counters pane. But how can I access this value?

I tried setting an attribute with the counter name, and counters property. Like ${filenamecounter} and ${filenamecounter.counter} but unsuccessful.

enter image description here

Upvotes: 2

Views: 5072

Answers (1)

Bryan Bende
Bryan Bende

Reputation: 18630

Currently counters are mostly a monitoring feature, you can't really access them from expression language. They're used to answer questions like "how many messages have I received from source xyz?".

In your case, all of the "split" processors should be writing a standard set of fragment attributes:

@WritesAttribute(attribute = "fragment.identifier",
    description = "All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute"),
@WritesAttribute(attribute = "fragment.index",
    description = "A one-up number that indicates the ordering of the split FlowFiles that were created from a single parent FlowFile"),
@WritesAttribute(attribute = "fragment.count",
    description = "The number of split FlowFiles generated from the parent FlowFile"),

So you should be able to use ${fragment.index} in your filename.

Upvotes: 3

Related Questions