Support Questions
Find answers, ask questions, and share your expertise

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

Solved Go to solution

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

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

Accepted Solutions

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

Super 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

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

Super 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