How to use value of a counter in NiFi

我的梦境 提交于 2020-06-27 16:36:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/46924082/how-to-use-value-of-a-counter-in-nifi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!