Table of Contents
- Guided Tour, part 1
- Guided Tour, part 3
This is continued from
Apache NiFi Guided Tour, part 1 in which we download and installed
NiFi, created a flow and ran it. In this part, we'll write a custom processor
(hint: it's already written), see how to test it statically using NiFi's JUnit
test framework outside the instance of Apache NiFi we set up and generate the
NAR.
In Apache NiFi Guided Tour, part 3
we'll inject our custom processor's NAR into the instance of Apache NiFi we
installed, then use our custom processor in a flow.
Setting up a custom-processor project
This exercise demonstrates setting up Apache NiFi, a custom-processor project
in IntelliJ IDEA and the creation of a NiFi flow using that processor.
The simple, custom NiFi processor accepts the following document:
This is a test of the Emergency Broadcast System. This is only a test.
The quick brown fox jumped over the lazy dog's back and got clean away.
...and changes the subject of the second sentence to "wily red fox" before
sending the resulting flowfile to the next NiFi processors in the flow.
Instructions for exploding and building this project in your local filesystem.
- Download
filter-exercise.tar.gz
to a suitable location in your local filesystem such as (e.g.:)
/home/user/dev.
- Explode it into the place you have chosen:
$ tar -zxf filter-exercise.tar.gz
- Launch IntelliJ IDEA (the Community Edition will suffice).
- Choose (click) to Open a project.
- Navigate to the parent directory where you exploded this project.
- Select filter and click OK.
-
Click Trust Project in the dialog presented. (For this project,
"trust" should only mean that you'll accept the IDEA and Maven
configuration as constituted to create the project. However, I cannot
guaranteed that no one has found a way to "jack" my download, so do this
nevertheless at your own risk.) At right, you see what I see in IntelliJ
IDEA.
- Open test source, FilterTest.java.
- In JUnit method, testWithProperty(), set a breakpoint on the
first line. Click the green triangle at the left and choose
Debug testWithProperty().
- Right-click on the line that calls method runTest( CONTENT )
and choose Run to Cursor. Notice that two dynamic properties
were created in the custom NiFi processor (named Filter).
- In the Debug window/pane, click the green triangle to finish
running the test case.
- Notice the test case output and that the original content has been
modified from "quick brown" to "wily red" in the resulting
flowfile. (This is what inputs to and output from a NiFi processor
are called.)
- This processor is a simple filter. How does it work? It performs its task
within the Apache NiFi custom processor framework. You can inspect this
code by looking at source file Filter.java, especially the
onTrigger() method at the top of that file. You'll find more
explanations at
Notes on writing a simple NiFi custom processor.
- Notice that a list of three attributes are printed out in the test case.
NiFi flowfiles always have attributes, particularly these three.
Next up, injecting filter-1.0.nar into our NiFi instance
See Apache NiFi Guided Tour, part 3:
Injecting a NiFi Custom-processor into an Installed Instance of Apache NiFi.