Alin Li NiFi Course

Data Flow Adventures โ€” Learn how data moves like magic!

v1.0 • 4 Modules • Ages 9-14
Module 1 of 4
Module 1

๐ŸŒŸ What is Apache NiFi & Why It Matters?

Discover the amazing tool that moves data around like a super-smart delivery service!

๐Ÿ“ฆ First โ€” What is Data?

Data is information. It's everywhere! Your name, your school grades, the temperature outside, photos on your phone, messages you send โ€” all of these are data.

Companies and organisations collect tons of data every second. Think about a weather station recording temperature every minute, or a shop tracking what people buy. All this data needs to move from one place to another to be useful.

๐Ÿ’ก Think of it like a Post Office!

Imagine millions of letters and packages arriving at a post office every day. Someone has to sort them, read the addresses, decide where they go, and deliver them. Apache NiFi does exactly this โ€” but for data!

๐Ÿ Meet Apache NiFi!

Apache NiFi is a free, open-source software that helps you collect, move, and deliver data between different systems automatically. It was originally created by the NSA (National Security Agency) in the USA and later given to the open-source community through the Apache Software Foundation.

The name "NiFi" comes from "NiagaraFiles" โ€” like the powerful Niagara Falls, it handles huge rivers of data flowing from one place to another!

๐Ÿ”“ It's Open Source!

NiFi is completely free to use, modify, and share. This aligns perfectly with the Alin Li mission of reviving the spirit of open computing. No paid licenses, no subscriptions โ€” just powerful, free software for everyone!

๐ŸŽฏ What Can NiFi Do?

NiFi is like a super-smart delivery service for data. Here's what it can do:

๐Ÿ“ฅ

Collect Data

Grab data from files, websites, sensors, databases, and more

๐Ÿ”„

Transform Data

Change data format, filter what you need, combine different sources

๐Ÿ“ค

Deliver Data

Send data to databases, files, cloud services, or other apps

๐Ÿ‘๏ธ

Monitor Everything

See exactly where your data is and what's happening to it in real-time

๐Ÿ”’

Keep It Safe

Encrypt data, control who can see it, and track every change

โšก

Handle Huge Loads

Process millions of data items per second without breaking a sweat

โš™๏ธ How Does NiFi Work? (The Big Picture)

NiFi uses a concept called "data flows". A data flow is like a recipe that tells NiFi: "Take data from HERE, do THIS to it, then send it THERE."

Here's a simple data flow:

๐Ÿ“ Source
Get the data
โžœ
โš™๏ธ Process
Change it
โžœ
๐Ÿ“‹ Queue
Wait in line
โžœ
๐Ÿ’พ Destination
Deliver it!
๐Ÿ’ก Think of it like a Factory Assembly Line!

Raw materials (data) come in โ†’ workers on the line (processors) shape and transform them โ†’ finished products (processed data) come out at the end. NiFi is the factory manager that controls the entire line!

๐Ÿ“– Key Terms โ€” Tap to Flip!

Learn the NiFi vocabulary by tapping each card:

๐Ÿ“„
FlowFile
tap to flip
A FlowFile is a single piece of data moving through NiFi. It has content (the actual data) and attributes (labels describing it).
โš™๏ธ
Processor
tap to flip
A Processor is a worker that does something with data โ€” reads a file, changes format, sends to a database, etc. NiFi has 300+ processors!
๐Ÿ”—
Connection
tap to flip
A Connection is the pipe between two processors. It holds a queue where FlowFiles wait before being processed.
๐Ÿ–ฅ๏ธ
Canvas
tap to flip
The Canvas is the main workspace where you drag-and-drop processors and connections to build your data flow visually!
๐Ÿ“Š
Provenance
tap to flip
Provenance is NiFi's history book โ€” it tracks every single thing that happened to every FlowFile. Perfect for debugging!
๐Ÿ“‚
Process Group
tap to flip
A Process Group is like a folder โ€” it organises related processors together to keep your canvas clean and tidy.

๐Ÿค” Why Should YOU Care About NiFi?

Even as a young learner, understanding data flow is super valuable because:

  • IoT Projects: If you have an ESP32 or Arduino collecting sensor data, NiFi can receive and store it automatically!
  • Future-proof skills: Data engineering is one of the most in-demand jobs in the world right now.
  • Visual programming: NiFi uses drag-and-drop โ€” no complicated coding needed to start!
  • It's free and open source: Perfect for learning without spending a single riyal!

๐Ÿงช Module 1 Quiz โ€” Test Your Knowledge!

1. What does NiFi stand for?

A) Network Interface Files
B) NiagaraFiles
C) New Internet Flow Integration

2. What is a FlowFile in NiFi?

A) A type of processor
B) The main NiFi application
C) A single piece of data moving through NiFi

3. NiFi is open-source software. What does that mean?

A) Free to use, modify, and share
B) Only free for students
C) Requires a paid license

4. What is the Canvas in NiFi?

A) A database where data is stored
B) The visual workspace where you build data flows
C) A type of connection
Module 2

๐Ÿ› ๏ธ Installation & Setup

Let's get NiFi running on your computer โ€” it's easier than you think!

๐Ÿ“‹ What You Need Before Starting

Before installing NiFi, make sure you have:

  1. A computer running Linux (recommended!), Windows, or macOS.
  2. Java 21 or newer installed. NiFi runs on Java, so this is essential.
  3. At least 4 GB of RAM (8 GB is better for smooth performance).
  4. A web browser โ€” Firefox (our open-source favourite!) or Chromium.
๐Ÿง Why Linux?

At Alin Li, we love Linux because it's free, open-source, and perfectly suited for running server applications like NiFi. Most NiFi installations in the real world run on Linux!

โ˜• Step 1: Install Java (OpenJDK)

NiFi needs Java to run. We'll install OpenJDK โ€” the free, open-source version of Java.

On Ubuntu/Debian Linux:

Terminal
# Update your system packages sudo apt update # Install OpenJDK 21 sudo apt install openjdk-21-jdk # Verify the installation java -version

You should see something like: openjdk version "21.0.x" โ€” that means Java is ready!

๐ŸชŸ On Windows?

Download OpenJDK from adoptium.net โ€” it's the free Java from the Eclipse Foundation. Run the installer and make sure to check "Set JAVA_HOME variable" during installation.

๐Ÿ“ฅ Step 2: Download Apache NiFi

Now let's download NiFi itself!

  1. Go to the official site: nifi.apache.org
  2. Click on "Downloads" in the navigation bar.
  3. Download the Binary file (the .zip file for all platforms).
  4. Extract the downloaded file to a folder you'll remember.

On Linux (using the terminal):

Terminal
# Navigate to your home directory cd ~ # Download NiFi (check nifi.apache.org for the latest version) wget https://downloads.apache.org/nifi/2.1.0/nifi-2.1.0-bin.zip # Extract the archive unzip nifi-2.1.0-bin.zip # Move to the NiFi folder cd nifi-2.1.0
โš ๏ธ Version Numbers Change!

The version number (2.1.0) will change over time. Always check the official NiFi website for the latest version before downloading.

๐Ÿš€ Step 3: Start NiFi!

Time to launch NiFi and see the magic happen!

On Linux/macOS:

Terminal
# Start NiFi in the background ./bin/nifi.sh start # Check the status ./bin/nifi.sh status # To stop NiFi later: ./bin/nifi.sh stop

On Windows:

Command Prompt
REM Navigate to the NiFi bin folder cd C:\nifi-2.1.0\bin REM Start NiFi run-nifi.bat
โณ Be Patient!

NiFi takes about 30-60 seconds to start up. It's loading all its powerful processors and tools in the background. Wait until you see "NiFi has started" in the log.

๐ŸŒ Step 4: Open the NiFi Web Interface

NiFi has a beautiful web-based interface. Open your browser and go to:

https://localhost:8443/nifi

NiFi 2.x generates a random username and password on first start. You'll find them in the log:

Terminal
# Find the generated credentials grep -i "Generated Username" logs/nifi-app.log grep -i "Generated Password" logs/nifi-app.log
๐Ÿ”’ HTTPS by Default

NiFi 2.x uses HTTPS (secure connection) by default on port 8443. Your browser may show a security warning โ€” this is normal for a local self-signed certificate. Click "Advanced" โ†’ "Proceed" to continue.

Once logged in, you'll see the NiFi Canvas โ€” your blank workspace ready for building data flows!

๐Ÿ—บ๏ธ Quick Tour of the NiFi Interface

The NiFi interface has these main parts:

๐Ÿ“

Toolbar

Top bar with icons for adding processors, labels, and other components

๐ŸŽจ

Canvas

The big white area where you drag-and-drop to build flows

๐Ÿ“Š

Status Bar

Shows how many processors are running, stopped, or have errors

โš™๏ธ

Operate Panel

Controls to start, stop, and configure your data flow

๐Ÿงช Module 2 Quiz โ€” Installation Check!

1. What do you need to install BEFORE NiFi?

A) Python
B) Node.js
C) Java (OpenJDK)

2. What is the default web address to access NiFi?

A) http://localhost:8080
B) https://localhost:8443/nifi
C) http://nifi.local:3000

3. Which command starts NiFi on Linux?

A) ./bin/nifi.sh start
B) nifi --run
C) sudo start nifi
Module 3

๐Ÿ”— Building Data Flows

Time to build your first data flow โ€” drag, drop, connect, and watch data move!

๐Ÿงฑ The Building Blocks of a Data Flow

Every NiFi data flow is made from just a few building blocks:

๐Ÿ“ฅ Source
Processor
โžœ
๐Ÿ“‹ Connection
(Queue)
โžœ
๐Ÿ”„ Transform
Processor
โžœ
๐Ÿ“‹ Connection
(Queue)
โžœ
๐Ÿ“ค Destination
Processor

That's it! With just processors and connections, you can build incredibly powerful data flows. Let's learn about each piece.

โš™๏ธ Understanding Processors

Processors are the workers of NiFi. Each processor does ONE specific job. NiFi comes with over 300 built-in processors! Here are the most important ones for beginners:

Processor What It Does Category
GetFile Reads files from a folder on your computer Source
PutFile Writes data to a file on your computer Destination
GenerateFlowFile Creates test data for experimenting Source
LogAttribute Prints FlowFile details to the log (for debugging) Utility
UpdateAttribute Changes or adds labels (attributes) to a FlowFile Transform
ReplaceText Finds and replaces text inside FlowFile content Transform
RouteOnAttribute Sends data to different paths based on conditions Transform
ListenHTTP Receives data sent over HTTP (from websites, IoT, etc.) Source
InvokeHTTP Calls websites or APIs to get or send data Utility

๐ŸŽ‰ Build Your First Flow: Generate โ†’ Log!

Let's build the simplest possible flow to see NiFi in action!

  1. Drag a Processor from the toolbar onto the canvas. Search for GenerateFlowFile and add it.
  2. Drag another Processor. Search for LogAttribute and add it.
  3. Connect them: Hover over GenerateFlowFile until you see a connection arrow. Drag it to LogAttribute. In the popup, check "success" and click "Create".
  4. Configure GenerateFlowFile: Double-click it โ†’ go to "Scheduling" tab โ†’ set "Run Schedule" to 5 sec (so it generates data every 5 seconds).
  5. Auto-terminate LogAttribute: Double-click LogAttribute โ†’ "Relationships" tab โ†’ check the box for "success" to auto-terminate.
  6. Start both processors: Right-click each โ†’ "Start" (or select all and press the โ–ถ play button in the toolbar).
GenerateFlowFile
Creates test data
โžœ
๐Ÿ“‹ Queue
โžœ
LogAttribute
Logs to console
๐ŸŽŠ Congratulations!

You've just built your first NiFi data flow! Check the NiFi logs to see the FlowFile attributes being printed. You can find logs at: logs/nifi-app.log

๐Ÿ“ Second Flow: GetFile โ†’ PutFile (File Mover!)

Let's build a flow that automatically moves files from one folder to another!

  1. Create two folders: ~/nifi-input and ~/nifi-output
  2. Add a GetFile processor โ†’ configure "Input Directory" to /home/yourname/nifi-input
  3. Add a PutFile processor โ†’ configure "Directory" to /home/yourname/nifi-output
  4. Connect GetFile โ†’ PutFile (relationship: "success")
  5. Auto-terminate PutFile's "success" and "failure" relationships
  6. Start both processors!
Terminal โ€” Create test folders
# Create input and output folders mkdir ~/nifi-input ~/nifi-output # Create a test file echo "Hello from Alin Li NiFi Course!" > ~/nifi-input/test.txt # Watch the output folder ls ~/nifi-output

Within seconds, the test file will magically appear in the output folder! ๐Ÿช„

๐Ÿ“‹ Understanding Connections & Queues

The lines between processors are called Connections. Each connection has a queue where FlowFiles wait.

๐Ÿ’ก Think of it like a Conveyor Belt!

Imagine a conveyor belt between two workers. If Worker B is slower than Worker A, packages pile up on the belt. In NiFi, FlowFiles pile up in the queue. You can see exactly how many are waiting by looking at the number on the connection!

Queue features you should know:

  • Back Pressure: If a queue gets too full, NiFi automatically slows down the source processor. Smart!
  • Prioritisation: You can set rules like "oldest first" or "newest first".
  • Expiration: FlowFiles can be set to expire if they wait too long.

๐ŸŽฎ Activity: Match the Processor to its Job!

Drag each processor name to the correct description:

GetFile
PutFile
ListenHTTP
ReplaceText
Reads files from a folder
Writes data to a file
Receives HTTP requests
Finds & replaces text

๐Ÿงช Module 3 Quiz โ€” Flow Builder!

1. What is the correct order of a basic data flow?

A) Source โ†’ Connection โ†’ Transform โ†’ Connection โ†’ Destination
B) Destination โ†’ Source โ†’ Connection
C) Transform โ†’ Source โ†’ Destination

2. What does the GenerateFlowFile processor do?

A) Reads files from a folder
B) Sends data to a database
C) Creates test data for experimenting

3. What happens when a NiFi queue gets full?

A) NiFi crashes
B) Back pressure slows down the source processor
C) All data is deleted
Module 4

๐Ÿš€ Real-World Projects

Apply your NiFi skills to exciting real projects โ€” IoT sensors, web APIs, and file routing!

๐ŸŒก๏ธ Project 1: IoT Temperature Logger with ESP32

Collect temperature data from an ESP32 sensor and save it with NiFi!

The Idea: Your ESP32 reads a temperature sensor and sends the reading to NiFi over WiFi. NiFi receives it, adds a timestamp, and saves it to a file. This is exactly how real IoT systems work!

๐Ÿ“Ÿ ESP32 Side (Arduino IDE)

This sketch connects your ESP32 to WiFi and sends temperature to NiFi every 10 seconds:

Arduino IDE โ€” ESP32 Sketch
// ============================================ // Alin Li NiFi IoT Temperature Logger v1.0 // ESP32 โ†’ NiFi via HTTP POST // ============================================ #include <WiFi.h> #include <HTTPClient.h> // WiFi credentials const char* ssid = "AlinLi_NiFi"; const char* password = "12345678"; // NiFi ListenHTTP address // Change this IP to your NiFi server's IP const char* nifiURL = "http://192.168.4.1:9090/iot"; // Simulated temperature (replace with real sensor) float readTemperature() { return 20.0 + (random(0, 150) / 10.0); } void setup() { Serial.begin(115200); // Connect to WiFi WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected! IP: " + WiFi.localIP().toString()); } void loop() { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; http.begin(nifiURL); http.addHeader("Content-Type", "application/json"); // Build JSON payload float temp = readTemperature(); String payload = "{\"device\":\"ESP32-01\","; payload += "\"temperature\":" + String(temp, 1) + ","; payload += "\"unit\":\"C\"}"; // Send POST request to NiFi int httpCode = http.POST(payload); if (httpCode > 0) { Serial.println("Sent: " + payload + " โ†’ Response: " + String(httpCode)); } else { Serial.println("Error sending data!"); } http.end(); } // Send every 10 seconds delay(10000); }

๐Ÿ”„ NiFi Side โ€” Build This Flow:

ListenHTTP
Port 9090, Path /iot
โžœ
UpdateAttribute
Add timestamp
โžœ
PutFile
Save to folder
  1. Add ListenHTTP โ†’ set Port to 9090 and Base Path to /iot
  2. Add UpdateAttribute โ†’ add property: filename = temp_${now():format('yyyyMMdd_HHmmss')}.json
  3. Add PutFile โ†’ set Directory to /home/yourname/iot-data
  4. Connect them: ListenHTTP โ†’ UpdateAttribute โ†’ PutFile
  5. Start all processors and run the ESP32!
๐Ÿ“‚ Result

Every 10 seconds, a new JSON file will appear in your iot-data folder with the temperature reading from the ESP32! You're now running a real IoT data pipeline!

๐ŸŒค๏ธ Project 2: Weather Data Collector from API

Fetch weather data from a free API and save it automatically!

The Idea: NiFi will call a free weather API every 5 minutes, get the current weather data, and save it to a file. Over time, you'll build a weather history database!

๐Ÿ”„ NiFi Flow:

GenerateFlowFile
Triggers every 5 min
โžœ
InvokeHTTP
Call weather API
โžœ
UpdateAttribute
Set filename
โžœ
PutFile
Save weather data
  1. Add GenerateFlowFile โ†’ Scheduling: Run every 5 min
  2. Add InvokeHTTP โ†’ set "HTTP URL" to a free weather API like:
    https://api.open-meteo.com/v1/forecast?latitude=25.29&longitude;=51.53¤t;_weather=true
    (This is for Doha! Change coordinates for your city)
  3. Add UpdateAttribute โ†’ set filename: weather_${now():format('yyyyMMdd_HHmm')}.json
  4. Add PutFile โ†’ Directory: /home/yourname/weather-data
  5. Connect and start!
๐Ÿ†“ Open-Meteo API

Open-Meteo is a completely free, open-source weather API โ€” no API key needed! It's perfect for learning and aligns with our open-source values.

๐Ÿ“‚ Project 3: Smart File Router

Automatically sort files into folders based on their type!

The Idea: Drop any file into an "inbox" folder, and NiFi will automatically sort it โ€” PDFs go to one folder, images to another, text files to a third!

๐Ÿ”„ NiFi Flow:

GetFile
Watch inbox
โžœ
RouteOnAttribute
Check file type
โžœ
PutFile ร—3
Sort into folders
  1. Create folders: inbox, sorted/pdf, sorted/images, sorted/text
  2. Add GetFile โ†’ Input Directory: your inbox folder
  3. Add RouteOnAttribute โ†’ Add routing rules:
    โ€ข pdf: ${filename:endsWith('.pdf')}
    โ€ข images: ${filename:endsWith('.jpg'):or(${filename:endsWith('.png')})}
    โ€ข text: ${filename:endsWith('.txt')}
  4. Add 3 PutFile processors โ€” one for each sorted folder
  5. Connect RouteOnAttribute's "pdf" โ†’ PutFile (pdf folder), "images" โ†’ PutFile (images), "text" โ†’ PutFile (text)
  6. Start and test by dropping different files into the inbox!
Terminal โ€” Create test folders & files
# Create the folder structure mkdir -p ~/inbox ~/sorted/pdf ~/sorted/images ~/sorted/text # Create test files echo "Hello" > ~/inbox/readme.txt touch ~/inbox/report.pdf touch ~/inbox/photo.jpg # Watch them get sorted automatically! ls ~/sorted/pdf ~/sorted/images ~/sorted/text
๐Ÿง  NiFi Expression Language

The ${filename:endsWith('.pdf')} syntax is called NiFi Expression Language (EL). It's a powerful mini-language for working with FlowFile attributes. You'll use it a lot as you build more complex flows!

๐ŸŒˆ What's Next? Keep Exploring!

You've learned the fundamentals of Apache NiFi! Here are some exciting things to try next:

๐Ÿ—„๏ธ

Connect to Databases

Use PutDatabaseRecord to store data in MySQL, PostgreSQL, or SQLite

๐Ÿ“ง

Send Alerts

Use PutEmail to send yourself alerts when something interesting happens

๐Ÿ”—

Chain Multiple APIs

Get data from one API, transform it, and send it to another

๐Ÿ“Š

Build Dashboards

Connect NiFi to Grafana to visualise your IoT data in real-time

๐Ÿงช Final Quiz โ€” Project Master!

1. Which processor receives HTTP requests from an ESP32?

A) InvokeHTTP
B) ListenHTTP
C) GetHTTP

2. Which processor sends HTTP requests to an API?

A) ListenHTTP
B) GetFile
C) InvokeHTTP

3. What does RouteOnAttribute do?

A) Sends data to different paths based on conditions
B) Changes the content of a FlowFile
C) Deletes FlowFiles that match a pattern

4. In NiFi Expression Language, what does ${filename:endsWith('.pdf')} check?

A) If the file content contains "pdf"
B) If the filename ends with ".pdf"
C) If the file size is large enough for a PDF

๐Ÿ† Course Complete!

Congratulations on completing the Alin Li NiFi Course โ€” Data Flow Adventures!

You've learned how to install NiFi, build data flows, and create real IoT and API projects. Keep exploring, keep building, and remember:

"Reviving the spirit of open computing" ๐ŸŒŸ