Using flowfile size as an argument in RouteOnAttribute nifi
Asked Answered
R

3

8

I want to know if is it possible to use flowfile size as an argument in routeOnAttribute i want to make expression like that :

${filename.fileSize>500}

but it tells me that expression ought to return true and my expression returns string what should i do to be able to make new connection in routeOnAttribute(p.s filename is my flowfile name)

EDIT 05/17/2019 Correct answer is Andy's. That is the best guidance from us (Apache NiFi team) on the subject. The answer marked "correct" only applies in a few cases where Content-Length is set by an upstream processor. Andy's solution, fileSize is universally applicable.

Ringtailed answered 24/8, 2017 at 6:40 Comment(5)
Why you are comparing file Size?.FileSize is not an attribute in which you use.Lodmilla
I want to check if the flowfile size is less than 500( it means response is empty) and i can make connection with emty reponse and then log it. should i use conetn size instead of size ?Ringtailed
I meand content lengthRingtailed
Yes you can use ${Content-Length}Lodmilla
ok thank you I have made it like this ${Content-Length:toNumber():divide(500):equals(1)}Ringtailed
L
-2

Two ways to check empty response present in flowfile.

1.Using Content-Length attribute-->${Content-Length}

2.Using Extract Text processor to extracts entire content in attribute.

flow_content--(.*)

then check ${flow_content:isEmpty():not()}

It may be helpful for your case.

Lodmilla answered 24/8, 2017 at 8:37 Comment(1)
It is far preferable to use ${Content-Length} because extracting the content to an attribute when the content is large will have a very detrimental effect on the performance of the application. Attributes are held in memory and written to the flowfile repository, which is designed for fast read/write and lightweight data. It is highly discouraged to extract the entire flowfile contents to an attribute just to check the size.Deflagrate
D
21

Your expression is logically correct but does not use valid Apache NiFi syntax. It should use the gt function as below:

${fileSize:gt(500)}

This will return a boolean result.

Deflagrate answered 24/8, 2017 at 19:0 Comment(0)
O
0

On the RouteOnAttribute, you can configure an attribute whose value evaluates to true when flowfile content is of certain size.

enter image description here

Orvah answered 14/2, 2022 at 20:12 Comment(0)
L
-2

Two ways to check empty response present in flowfile.

1.Using Content-Length attribute-->${Content-Length}

2.Using Extract Text processor to extracts entire content in attribute.

flow_content--(.*)

then check ${flow_content:isEmpty():not()}

It may be helpful for your case.

Lodmilla answered 24/8, 2017 at 8:37 Comment(1)
It is far preferable to use ${Content-Length} because extracting the content to an attribute when the content is large will have a very detrimental effect on the performance of the application. Attributes are held in memory and written to the flowfile repository, which is designed for fast read/write and lightweight data. It is highly discouraged to extract the entire flowfile contents to an attribute just to check the size.Deflagrate

© 2022 - 2024 — McMap. All rights reserved.