Monday, 21 September 2026

Apache NiFi Tutorial: Building a Simple File Monitoring Pipeline

  

One of the best ways to learn Apache NiFi is by building a simple end-to-end data flow. In this post, we will create a basic flow that:

 

Reads files from a local directory using the GetFile processor.

Displays FlowFile metadata using the LogAttribute processor.

Runs the flow and verifies the results in the NiFi application logs.

 

This example introduces several core NiFi concepts:

 

·      Process Groups

·      Processors

·      FlowFiles

·      Connections

·      Data Flow Execution

·      FlowFile Attributes

 

According to the Apache NiFi Getting Started Guide, a FlowFile represents a piece of user data moving through NiFi, while a Processor is responsible for creating, receiving, transforming, routing, and processing FlowFiles. The GetFile processor is commonly used to ingest files from a local filesystem into NiFi.

 

Follow below step-by-step procedure to build the NiFi DataFlow.

 

Step 1: Open the NiFi UI

Start NiFi and open the web interface https://localhost:8443.

 

After logging in, you will see the NiFi canvas.

 


Step 2: Create a Process Group

Rather than building everything on the root canvas, it is a good practice to organize flows inside a Process Group.

 


Drag the Process Group icon onto the canvas.

 

Give the name as 'File Processing Demo'

 


Click on Add button.

 

You will now see a Process Group on the canvas.

 


Step 3: Enter the Process Group

Double-click the newly created Process Group.

 

You are now inside an isolated workspace where you can build your flow.

 

Think of a Process Group as a folder that contains related processors, connections, controller services, and other flow components.

 

Step 4: Add the GetFile Processor

The GetFile processor reads files from a directory and creates FlowFiles for each file found.

 

Drag a Processor onto the canvas.

 

Search for 'GetFile', Select GetFile.

 


Click on Add button.

 

Step 5: Configure GetFile

 

Right-click the processor and select -> Configure.

 

Navigate to the Properties tab. Set input directory to some valid folder path.

 


Click Apply.

 

Step 6: Add the LogAttribute Processor

The LogAttribute processor writes FlowFile attributes to the NiFi application log. It is extremely useful for learning how FlowFiles move through a data flow.

 

Drag another Processor onto the canvas.

 

Search for LogAttribute, Select it.

 

Click Add.

 

Step 7: Connect the Processors

Now we need to tell NiFi where FlowFiles should go after GetFile processes them.

 

Hover over GetFile.

 

Drag the connection arrow to LogAttribute.

 

A dialog appears showing relationships.

 

Select the checkbox against 'success'.

 


   

Click Add.

 

The flow now looks like below.

 

 

As you observe above DataFlow image, there is a warning message against LogAttribute processor. Hover mouse to see the actual error.


   

The error quotest like below:

 

'Relationship success' is invalid because Relationship 'success' is not connected to any component and is not auto-terminated'Relationship success' is invalid because Relationship 'success' is not connected to any component and is not auto-terminated

 

How to address above issue?

NiFi requires every relationship to be handled in one of two ways:

 

Connected to another processor

Marked as Auto-Terminate

 

If neither is done, NiFi doesn't know what to do with the FlowFile, so the processor is considered invalid.

 

To address this issue, right click on LogAttribute processor -> Configure. Click on Relationships tab and select terminate checkbox.

 


Click on Apply button.

 

You can observe that the warning message disappears now.

 

   

Step 8: Start the Processors

 

Right click on the canvas -> Start.

 


It starts both the processors.

 

The processor icons should turn green. This indicates that NiFi is actively polling the input directory and processing files.

 

Step 9: Create a Test File

 

Open a terminal and create a sample file:

echo "Hello NiFi" > /Users/Shared/NiFi/inputDir/sample.txt

 

Replace the directory ‘/Users/Shared/NiFi/inputDir/’ with the input directory you set while configuring GetFile processor.

 

The GetFile processor will detect the file and convert it into a FlowFile. The FlowFile is then transferred to LogAttribute.

 

Step 10: Verify the Flow

 

The LogAttribute processor writes FlowFile information to the NiFi application log. Open a terminal and run:

 

tail -f logs/nifi-app.log

 

You can able to see following log messages.

 

--------------------------------------------------
FlowFile Properties
Key: 'entryDate'
	Value: 'Tue Jun 16 14:43:25 IST 2026'
Key: 'lineageStartDate'
	Value: 'Tue Jun 16 14:43:25 IST 2026'
Key: 'fileSize'
	Value: '11'
FlowFile Attribute Map Content
Key: 'absolute.path'
	Value: '/Users/Shared/NiFi/inputDir/'
Key: 'file.creationTime'
	Value: '2026-06-16T14:43:25+0530'
Key: 'file.group'
	Value: 'wheel'
Key: 'file.lastAccessTime'
	Value: '2026-06-16T14:43:25+0530'
Key: 'file.lastModifiedTime'
	Value: '2026-06-16T14:43:25+0530'
Key: 'file.owner'
	Value: 'h0g01ex'
Key: 'file.permissions'
	Value: 'rw-r--r--'
Key: 'filename'
	Value: 'sample.txt'
Key: 'path'
	Value: '/'
Key: 'uuid'
	Value: '0b9c32ed-daa5-4d62-a527-bfa9f8196ded'
--------------------------------------------------

   

This simple flow forms the foundation for almost every NiFi pipeline. Once comfortable with GetFile and LogAttribute, you can continue by adding processors such as:

 

·      UpdateAttribute

·      RouteOnAttribute

·      ReplaceText

·      PutFile

·      ExecuteSQL

·      PutDatabaseRecord

 

to build more advanced data integration workflows.

  

Previous                                                    Next                                                    Home

Understanding FlowFiles and Processors in Apache NiFi

  

Before building dataflows in Apache NiFi, it is important to understand two fundamental concepts:

 

·      FlowFile: The data that moves through NiFi.

·      Processor: The component that performs actions on that data.

 

Think of NiFi as a large package delivery system:

 

·      FlowFiles are the packages being transported.

·      Processors are the workers who receive, inspect, modify, route, and deliver those packages.

 

Once you understand these two concepts, the rest of NiFi becomes much easier to learn.

 

1. FlowFile

A FlowFile is the basic unit of data in Apache NiFi. Whenever data enters NiFi, it is wrapped inside a FlowFile and then moves through the dataflow from one Processor to another.

 

Examples of data that can become FlowFiles:

 

·      CSV files

·      JSON files

·      XML documents

·      Images

·      Log files

·      Database records

·      Messages from Kafka

·      API responses

 

In simple terms, a FlowFile represents a piece of data traveling through a NiFi flow.

 


2. Structure of a FlowFile

A FlowFile consists of two parts Content and Attributes.

 

a. Content

The Content is the actual data.

 

Example 1: JSON Content

 

{
  "id": 1,
  "name": "Krishna",
  "city": "Bangalore"
}

   

Example 2: CSV Content

 

id,name,city
101,Krishna,Bangalore

   

Example 3: Log Content

 

2025-06-16 ERROR Database Connection Failed

   

Everything inside the data itself is called the Content.

 

b. Attributes

Attributes are metadata about the content. They are stored as key-value pairs. Following are some of the key attributes of FlowFile.

 

·      path: The FlowFile's path indicates the relative directory to which a FlowFile belongs and does not contain the filename

·      filename: The filename of the FlowFile. The filename should not contain any directory structure.

·      uuid: A unique UUID assigned to this FlowFile

·      priority: A numeric value indicating the FlowFile priority

·      mime.type: The MIME Type of this FlowFile

·      discard.reason: Specifies the reason that a FlowFile is being discarded

·      alternate.identifier: Indicates an identifier other than the FlowFile's UUID that is known to refer to this FlowFile.

 

3. Real-World Example

Imagine a courier package. The package contains a Laptop. This is equivalent to the Content.

 

The shipping label contains:

·      Sender: Amazon

·      Receiver: Hari

·      Destination: Chennai

·      Priority: High

 

This is equivalent to the Attributes. Just as a courier company routes packages using labels, NiFi routes FlowFiles using attributes.

 

4. Why Attributes Are Important

Reading file content can be expensive. Instead of opening every file, NiFi can make decisions based on attributes.

 

For example: If country = UK, then route the FlowFile to the UK processing pipeline. If country = India, then route the FlowFile to the India processing pipeline. This makes processing much faster.

 

5. FlowFile Lifecycle

A typical FlowFile journey looks like this:

Data Source
    ↓
FlowFile Created
    ↓
Processor 1
    ↓
Processor 2
    ↓
Processor 3
    ↓
Destination

Example:
CSV File
    ↓
GetFile
    ↓
ValidateRecord
    ↓
ConvertRecord
    ↓
PutDatabaseRecord

   

At every step, the FlowFile continues traveling through the flow.

 

In the above flow diagram, a Processor is the component that performs work on FlowFiles. Processors are the building blocks of every NiFi dataflow. Without Processors, FlowFiles cannot move or be processed.

 

Think of a Processor as a worker in a factory. Each worker performs a specific task before passing the item to the next worker.

 

2. Processors

A Processor is the component that performs work on FlowFiles. Processors are the building blocks of every NiFi dataflow. Without Processors, FlowFiles cannot move or be processed.

 

Think of a Processor as a worker in a factory. Each worker performs a specific task before passing the item to the next worker.

 

A Processor can:

·      Create FlowFiles (Ex: GenerateFlowFile)

·      Receive FlowFiles (Ex: GetFile, ConsumeKafka, ListenHTTP, GetSFTP)

·      Transform FlowFiles (Ex: Convert CSV → JSON, Convert XML → JSON, Modify Fields or content, Mask Sensitive Data)

·      Route FlowFiles (Ex: Send data to different paths based on conditions)

·      Split FlowFiles

·      Merge FlowFiles

·      Send FlowFiles to External Systems

 


2.1 Processor Analogy

Imagine an airport baggage handling system.

 

 

Suitcase Arrives
      ↓
Security Check
      ↓
Weight Check
      ↓
Destination Check
      ↓
Loaded onto Flight

   

Each station performs a specific task.

In NiFi:

 

FlowFile Arrives
      ↓
Processor A
      ↓
Processor B
      ↓
Processor C
      ↓
Destination

   

 

Each Processor performs one responsibility.

 

2.2 Commonly Used Processors

Following table summarizes commonly used processors by Beginners.

 

Processor       

Purpose                  

GenerateFlowFile

Create sample FlowFiles

GetFile         

Read files from disk     

PutFile         

Write files to disk      

UpdateAttribute 

Add or modify attributes 

RouteOnAttribute

Route based on attributes

ReplaceText     

Modify content           

SplitJson       

Split JSON documents     

MergeContent    

Merge FlowFiles          

ConsumeKafka    

Read from Kafka          

PublishKafka    

Write to Kafka           

 

2.3 FlowFile and Processor Working Together

Consider a simple file ingestion flow:

 

Customer.csv
      ↓
GetFile
      ↓
UpdateAttribute
      ↓
RouteOnAttribute
      ↓
PutFile

   

Here:

·      GetFile: Reads "Customer.csv" and creates a FlowFile.

·      UpdateAttribute: Adds attributes like sourceSystem=CRM, country=UK etc.,

·      RouteOnAttribute: Checks country=UK and routes to UK pipeline.

·      PutFile: Stores the file in the target location.

 

 

+------------------+
|   Customer.csv   |
+------------------+
          |
          v
+------------------+
|     GetFile      |
+------------------+
          |
          v
+------------------+
| UpdateAttribute  |
+------------------+
          |
          v
+------------------+
| RouteOnAttribute |
+------------------+
          |
          v
+------------------+
|     PutFile      |
+------------------+

   

The file travels as a FlowFile, while each box is a Processor performing an action.

 

In sumamry:

·      FlowFile is the fundamental unit of data in NiFi. It contains Content (actual data) and attributes (metadata). FlowFile move throught the data flow.

 

·      Processor is the Core building block of NiFi. It performs actions on FlowFiles and Processors can create, receive, transform, route, split, merge, and send data.

 

Understanding these two concepts is the foundation for learning Apache NiFi, because every NiFi flow is ultimately built by moving FlowFiles through a series of Processors.

 

 

Previous                                                    Next                                                    Home