Created 09-03-2020 03:34 PM
I would like know how I can to retrieve content of my flow file.
First I have Kafka Consumer processor which consume message from Kafka Cluster and prepare flow file for the message then flow pass to ExecuteScript Processor where I need to get the message from Flow File so that I can create a new FlowFile attrubite using that and send it to next processor.
I can view the message by clilcking on List Queue--> View button which show the content of Flow File (Actual Kafka Message). But I dont know how I can read the content of FlowFile in ExecuteScript Processor.
Please suggest.
Thank You,
Created 09-04-2020 12:06 AM
Hi....you haven't mentioned what kind of script you are planning to use. Assuming you are using Groovy here is a sample script that should work :
def flowFile = session.get()
if(!flowFile) return
flowFile = session.write(flowFile, { inputStream, outputStream ->
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))
String dummy = flowFile.getAttribute('dummy')
br.eachLine { //your logic here } //only if you want to process per line
} as StreamCallback)
session.transfer(flowFile, REL_SUCCESS)
Hope this helps. If the comment helps you to find a solution or move forward, please accept it as a solution for other community members
Created 09-04-2020 06:20 AM
@DanMcCray1 Once you have the content from Kafka as a flowfile, your options are not just limited to ExecuteScript. Depending on the type of content you can use the following ideas:
If you indeed want to work with Execute Script you should start here:
https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922
https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018
https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-3/ta-p/249148
If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.
Thanks,
Steven @ DFHZ