Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Nifi:how to handle trnasfer 'transaction' based on flowFile amount in nifi?

avatar

I want to make transfer operation when i will have certain amount of flowFile in my flowFile queue, and i make remove operation for unused File . Can remove operation cause to dissapear flowfile from my flowfile array list ? here is my code:

  import org.apache.commons.io.IOUtils
    import java.nio.charset.StandardCharsets
    import groovy.lang.*
    
    def flowFile=session.get();
    def name=flowFile.getAttribute("realName")
    def count=flowFile.getAttribute("count")
    def  filename=flowFile.getAttribute("filename")
    def value= count as Double;
    def numb=Math.round(value)
    def List<FlowFile> flowFiles= new ArrayList<>();
    flowFiles.add(flowFile)
    
    if(flowFiles.size()==numb){
    for(FlowFile i in flowFiles){
    if(i.getAttribute("filename").substring(0,10)==name){
    session.transfer(i,REL_SUCCESS);
    
    }
    }
    }
    
    else{
    
    session.remove(flowFile);
    
    }


1 ACCEPTED SOLUTION

avatar
Master Guru

If you are waiting for X number of flow files to be received, you can use something like this (assuming you want 10 flow files):

def flowfileList = session.get(10)
if(flowfileList.size() < 10) {
  session.rollback()
  return
}
// If you get here, you have 10 flowfiles in flowfileList

View solution in original post

1 REPLY 1

avatar
Master Guru

If you are waiting for X number of flow files to be received, you can use something like this (assuming you want 10 flow files):

def flowfileList = session.get(10)
if(flowfileList.size() < 10) {
  session.rollback()
  return
}
// If you get here, you have 10 flowfiles in flowfileList