Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to manipulate text in NiFi processor IDE?

avatar
Contributor

I am trying to develop a custom processor to manipulate flowfile contents via Java. However, I am not sure how constructors are used for the flowfile contents. As a simplified example, how can I create a custom processor that replaces the letter A with the letter Z in a flowfile content?

1 ACCEPTED SOLUTION

avatar
Master Guru

For replacing contents of an incoming flowfile, the write(FlowFile, StreamCallback) method of ProcessSession is probably your best bet. There is a corresponding section of the NiFi Developer's Guide.

There is an example of this in the ReplaceText processor code under the AlwaysReplace strategy.

As an alternative to creating a full-fledged custom processor, as of NiFi 0.5.0 there are the InvokeScriptedProcessor and ExecuteScript processors. You can use InvokeScriptedProcessor to use a scripting language like Groovy to provide a Processor implementation, which avoids the need for building and deploying your own NARs. If you don't need a full processor and are just looking to manipulate the flowfile content, you could use the ExecuteScript processor, which allows easy access to incoming flowfiles and such.

I've written a blog post on using ExecuteScript (with Groovy) to replace flowfile contents: http://funnifi.blogspot.com/2016/02/executescript-processor-replacing-flow.html

Regards,

Matt

View solution in original post

2 REPLIES 2

avatar
Master Guru

For replacing contents of an incoming flowfile, the write(FlowFile, StreamCallback) method of ProcessSession is probably your best bet. There is a corresponding section of the NiFi Developer's Guide.

There is an example of this in the ReplaceText processor code under the AlwaysReplace strategy.

As an alternative to creating a full-fledged custom processor, as of NiFi 0.5.0 there are the InvokeScriptedProcessor and ExecuteScript processors. You can use InvokeScriptedProcessor to use a scripting language like Groovy to provide a Processor implementation, which avoids the need for building and deploying your own NARs. If you don't need a full processor and are just looking to manipulate the flowfile content, you could use the ExecuteScript processor, which allows easy access to incoming flowfiles and such.

I've written a blog post on using ExecuteScript (with Groovy) to replace flowfile contents: http://funnifi.blogspot.com/2016/02/executescript-processor-replacing-flow.html

Regards,

Matt

avatar
Contributor
@mburgess

I am using nifi-0.4.0. This version does not have the ExecuteScript processor. How can I install this processor and configure the processor to run a Java program?

-KS