Amarnatha Reddy
Amarnatha Reddy

Reputation: 15

How can we read nifi multiple flow files into groovy script

I have two flow flies and i want to read those two flow files in to groovy script and i am using the below line in my groovy to read the flow file content, but how do i know which flow file i am reading here, actually i want to compare two flow file content line by line in groovy and if the content is different then only i need to send the different content into output flow file from groovy script, Thank you.

def flowFile = session.get()
if(!flowFile) return

how do know from the above which flow file i am reading out of my two incoming flow files.

Upvotes: 0

Views: 213

Answers (1)

daggett
daggett

Reputation: 28564

In groovy processor this code session.get() returns first function from inbound queue.

The order (priority) of files in queue defined by it's properties:

https://nifi.apache.org/docs/nifi-docs/html/user-guide.html#settings

To read first 2 files from queue you can use an int parameter in session get:

def flowFileList = session.get(2)
if(!flowFileList) return
if(flowFileList.size()<2) {
    session.rollback() // return files back
    return
}
...

https://www.javadoc.io/doc/org.apache.nifi/nifi-api/latest/org/apache/nifi/processor/ProcessSession.html#get(int)

Upvotes: 0

Related Questions