hadoopgroovyclouderaapache-nifihortonworks-data-platform

nifi FlowFile has not been closed (Groovy script)warning


new to nifi terminologies and flowfile handling.

Found a convenient way to handle incoming xml and parse it using XmlSlurper, but getting a warning for the below GroovyScript for incoming flowfiles-

the flow: enter image description here

processor details: enter image description here

script body:

def flowFile = session.get()
if(!flowFile) return
InputStream i = flowFile.read()
new XmlSlurper().parse(i)
i.close()
REL_SUCCESS << flowFile

Seems like issue with handling the flowfile. Can someone explain what exactly is happening here and how to best handle it? seems like this is causing the cluster to hang at times warning


Solution

  • use try-catch or withStream to close stream even if error occured:

    def flowFile = session.get()
    if(!flowFile) return
    def xml = flowFile.read().withStream{i->
        new XmlSlurper().parse(i)
    }
    REL_SUCCESS << flowFile