Migrating Apache Flume Flows to Apache NiFi:  Any Relational Database To/From Anywhere
Tags: apachekafka, apachenifi, database, jdbc
Published: 2019-11-27 17:09:44

---
title: Migrating Apache Flume Flows to Apache NiFi:  Any Relational Database To/From Anywhere
published: true
date: 2019-10-15 15:58:00 UTC
tags: apache-kafka,apache-nifi,database,jdbc
canonical_url: 
---

### Migrating Apache Flume Flows to Apache NiFi:  Any Relational Database To/From Anywhere

**Article 8 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache\_42.html](https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache_42.html)  
**Article 7 - This**  
**Article 6 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache\_9.html](https://dev.to/tspannhw/migrating-apache-flume-flows-to-apache-nifi-kafka-source-to-http-rest-sink-and-http-rest-source-to-kafka-sink-3fce-temp-slug-1034225)  
**Article 5 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache\_35.html](https://dev.to/tspannhw/migrating-apache-flume-flows-to-apache-nifi-syslog-to-kafka-2g4-temp-slug-8252770)  
**Article 4 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache\_8.html](https://dev.to/tspannhw/migrating-apache-flume-flows-to-apache-nifi-twitter-source-to-kafka-sink-2f5o-temp-slug-2494436)

**Article 3 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache\_7.html](https://dev.to/tspannhw/migrating-apache-flume-flows-to-apache-nifi-kafka-source-to-apache-parquet-on-hdfs-19o3-temp-slug-1137778)

**Article 2 - ** [https://www.datainmotion.dev/2019/10/migrating-apache-flume-flows-to-apache.html](https://dev.to/tspannhw/migrating-apache-flume-flows-to-apache-nifi-kafka-source-to-hdfs-kudu-file-hive-3iec-temp-slug-5337136)

**Article 1**  - [https://www.datainmotion.dev/2019/08/migrating-apache-flume-flows-to-apache.html](https://www.datainmotion.dev/2019/08/migrating-apache-flume-flows-to-apache.html)

**Source Code:  ** [https://github.com/tspannhw/flume-to-nifi](https://github.com/tspannhw/flume-to-nifi)  
  

[![](https://1.bp.blogspot.com/-Ki8-YkPFerg/XaiyIbmNFkI/AAAAAAAAYn0/cwpDHfEamckH82RWhBS4LU0jsCiT9UHSACLcBGAsYHQ/s640/rdbmsicon.png)](https://1.bp.blogspot.com/-Ki8-YkPFerg/XaiyIbmNFkI/AAAAAAAAYn0/cwpDHfEamckH82RWhBS4LU0jsCiT9UHSACLcBGAsYHQ/s1600/rdbmsicon.png)
  
  

This is a simple use case of being a gateway between Relational Databases and other sources and sinks.   We can do a lot more than that in NiFi.  We can SELECT, UPDATE, INSERT, DELETE and run any DML.  All with No Code.   We can also access metadata from an RDBMS and build dynamical ELT systems from that.  
  
It is extremely easy to do this in NiFi.  
  

[![](https://1.bp.blogspot.com/-i2rLfmX7zgQ/XaizcpCYTcI/AAAAAAAAYoA/q7TJrbKZ3QoooqxXhI9O5-oBxP4ze7E1ACLcBGAsYHQ/s640/databaseflume.png)](https://1.bp.blogspot.com/-i2rLfmX7zgQ/XaizcpCYTcI/AAAAAAAAYoA/q7TJrbKZ3QoooqxXhI9O5-oBxP4ze7E1ACLcBGAsYHQ/s1600/databaseflume.png)

  

### Instead of using Flume, Let's Use Apache NiFi to Move Any Tabular Data To and From Databases

  

[![](https://1.bp.blogspot.com/-4Eknb6pcDaY/Xai1GOV2BJI/AAAAAAAAYoY/MhGche9acI8hvej_Y11OJEGpPdk3CzspwCLcBGAsYHQ/s640/classicphone.png)](https://1.bp.blogspot.com/-4Eknb6pcDaY/Xai1GOV2BJI/AAAAAAAAYoY/MhGche9acI8hvej_Y11OJEGpPdk3CzspwCLcBGAsYHQ/s1600/classicphone.png)

  

  

### **From A Relational Database (via JDBC Driver) to Anywhere.   In our case, we will pull from an RDBMS and post to Kudu.**

  

Step 1:  **QueryDatabaseTableRecord (Create Connection Pool, Pick DB Type, Table Name, Record Writer)**

Step 2:  **PutKudu (Set Kudu Master, Table Name, **

**Done!**

  

### **Query Database**

[![](https://1.bp.blogspot.com/-FrMs1o4EXrM/Xai3lJQxuyI/AAAAAAAAYpM/IOuTGDGMjUkQcXGcwJ34MYAV5Z5t__0KwCLcBGAsYHQ/s640/querydatabase.png)](https://1.bp.blogspot.com/-FrMs1o4EXrM/Xai3lJQxuyI/AAAAAAAAYpM/IOuTGDGMjUkQcXGcwJ34MYAV5Z5t__0KwCLcBGAsYHQ/s1600/querydatabase.png)

  

### Connect to Kudu

[![](https://1.bp.blogspot.com/-NgdU3evkfZQ/Xai1F3pHIgI/AAAAAAAAYoM/FX1oXmJqOyUmy1y3VB0QDpnfZBoJ-FNlQCLcBGAsYHQ/s640/PutKuduIoT.png)](https://1.bp.blogspot.com/-NgdU3evkfZQ/Xai1F3pHIgI/AAAAAAAAYoM/FX1oXmJqOyUmy1y3VB0QDpnfZBoJ-FNlQCLcBGAsYHQ/s1600/PutKuduIoT.png)

  

  

###   
Let's Write JSON Records That Get Converted to Kudu Records or RDBMS/MySQL/JDBC Records 

[![](https://1.bp.blogspot.com/-DMygQhCWCIc/Xai1GUSsFAI/AAAAAAAAYoU/D5Cu1srJd30XQ44MYUqQoR6H_8kASl28QCLcBGAsYHQ/s640/jsonwriterinferschema.png)](https://1.bp.blogspot.com/-DMygQhCWCIc/Xai1GUSsFAI/AAAAAAAAYoU/D5Cu1srJd30XQ44MYUqQoR6H_8kASl28QCLcBGAsYHQ/s1600/jsonwriterinferschema.png)

  

  

### Schema For The Data

[![](https://1.bp.blogspot.com/-zvU98YgnQkg/Xai1Io0W2XI/AAAAAAAAYow/wYaJ4bgpA8gOZXxA1sLODVrqmbnJskGMgCLcBGAsYHQ/s640/schema.png)](https://1.bp.blogspot.com/-zvU98YgnQkg/Xai1Io0W2XI/AAAAAAAAYow/wYaJ4bgpA8gOZXxA1sLODVrqmbnJskGMgCLcBGAsYHQ/s1600/schema.png)

  

  

  

### Read All The Records From Our JDBC Database

[![](https://1.bp.blogspot.com/-ffqLC2HVm14/Xai1GyXwArI/AAAAAAAAYog/RaSLgWRto7c5cBJwLSzQQdm3LTOyZYBzgCLcBGAsYHQ/s640/manydatabaserecords.png)](https://1.bp.blogspot.com/-ffqLC2HVm14/Xai1GyXwArI/AAAAAAAAYog/RaSLgWRto7c5cBJwLSzQQdm3LTOyZYBzgCLcBGAsYHQ/s1600/manydatabaserecords.png)

  

[![](https://1.bp.blogspot.com/-2IXfIql5c1w/Xai1IQAD09I/AAAAAAAAYos/2g_yTHEIwJIY5wB-N5E9iRf6lAuh45IngCLcBGAsYHQ/s640/querydbRows.png)](https://1.bp.blogspot.com/-2IXfIql5c1w/Xai1IQAD09I/AAAAAAAAYos/2g_yTHEIwJIY5wB-N5E9iRf6lAuh45IngCLcBGAsYHQ/s1600/querydbRows.png)

  

  

### 

  

### Let's Create an Apache Kudu table to Put Database Records To

  

  

[![](https://1.bp.blogspot.com/-f86ATovCyKE/Xai1F13bIXI/AAAAAAAAYoQ/CvoAg_MVC08GsH7lq_lRwSOWQeT31-rqQCLcBGAsYHQ/s640/createkudutable.png)](https://1.bp.blogspot.com/-f86ATovCyKE/Xai1F13bIXI/AAAAAAAAYoQ/CvoAg_MVC08GsH7lq_lRwSOWQeT31-rqQCLcBGAsYHQ/s1600/createkudutable.png)

  

  

### Let's Examine the MySQL Table We Want to Read/Write To and From
  

[![](https://1.bp.blogspot.com/--aUv79lvme4/Xai1Gpm4GzI/AAAAAAAAYoc/MavSKTgrO2A5l4-1QGkkUVCmJNrocjKMQCLcBGAsYHQ/s640/iotResultsMySql.png)](https://1.bp.blogspot.com/--aUv79lvme4/Xai1Gpm4GzI/AAAAAAAAYoc/MavSKTgrO2A5l4-1QGkkUVCmJNrocjKMQCLcBGAsYHQ/s1600/iotResultsMySql.png)
  

  

  

### Let's Check the MariaDB Table
  

[![](https://1.bp.blogspot.com/-yhj4Ew1j1H8/Xai1Hd2AmWI/AAAAAAAAYok/27a0UNk8Y74U6FQFR0qEfqi0kA-ayGlOACLcBGAsYHQ/s640/mariacount.png)](https://1.bp.blogspot.com/-yhj4Ew1j1H8/Xai1Hd2AmWI/AAAAAAAAYok/27a0UNk8Y74U6FQFR0qEfqi0kA-ayGlOACLcBGAsYHQ/s1600/mariacount.png)

  

### MySQL Table Information
  

[![](https://1.bp.blogspot.com/-olShx-4AfD8/Xai1H1NfckI/AAAAAAAAYoo/wufzXAAaMacznbfK3Y3XfXzxybrO4ayVgCLcBGAsYHQ/s640/mysqltable.png)](https://1.bp.blogspot.com/-olShx-4AfD8/Xai1H1NfckI/AAAAAAAAYoo/wufzXAAaMacznbfK3Y3XfXzxybrO4ayVgCLcBGAsYHQ/s1600/mysqltable.png)
  

  

  

  

### **From Anywhere (Say a Device) to A Relational Database (via JDBC Driver).   In our case, we will insert into an RDBMS from Kafka.**

  

Step 1:  **Acquire or modify data say ConsumeKafkaRecord\_2**

Step 2:  **PutDatabaseRecord (Set Record Reader, INSERT or UPDATE, Connection Pool, Table Name)**

**Done!**

  

  

### Put Database Records in Any JDBC/RDBMS

[![](https://1.bp.blogspot.com/-XqvmzTNlXS8/Xai4uZGOlgI/AAAAAAAAYpU/RkJBGhv3NiEhNxlGLdvHQ3plmEtHPoPOgCLcBGAsYHQ/s640/putdatabaserecord.png)](https://1.bp.blogspot.com/-XqvmzTNlXS8/Xai4uZGOlgI/AAAAAAAAYpU/RkJBGhv3NiEhNxlGLdvHQ3plmEtHPoPOgCLcBGAsYHQ/s1600/putdatabaserecord.png)

  

  

**Setup Your Connection Pool to SELECT, UPDATE, INSERT or DELETE**

[![](https://1.bp.blogspot.com/-_NIL-jAS-e4/Xai4uTIiVXI/AAAAAAAAYpY/76Liq_NSPskK1k-pJGIAhyUjmrZWvb6YACLcBGAsYHQ/s640/mariaconnectionpool.png)](https://1.bp.blogspot.com/-_NIL-jAS-e4/Xai4uTIiVXI/AAAAAAAAYpY/76Liq_NSPskK1k-pJGIAhyUjmrZWvb6YACLcBGAsYHQ/s1600/mariaconnectionpool.png)
  

  

  

  
  
**SQL DDL**  
  
**Create MariaDB/MySQL Table**  
  
  

CREATE TABLE iot ( uuid VARCHAR(255) NOT NULL PRIMARY KEY,

 ipaddress VARCHAR(255),top1pct BIGINT, top1 VARCHAR(255),

cputemp VARCHAR(255), gputemp VARCHAR(255),

 gputempf VARCHAR(255),

cputempf varchar(255), runtime VARCHAR(255),

host VARCHAR(255), filename VARCHAR(255),

 imageinput VARCHAR(255),hostname varchar(255),

macaddress varchar(255), end VARCHAR(255), te VARCHAR(255), systemtime VARCHAR(255),
  

cpu BIGINT, diskusage VARCHAR(255), memory BIGINT, id VARCHAR(255));
  
**Create Kudu Table**  
  
  

CREATE TABLE iot ( uuid STRING,

 ipaddress STRING,top1pct BIGINT, 

 top1 STRING,

cputemp STRING, 

gputemp STRING,

 gputempf STRING,

cputempf STRING, runtime STRING,

host STRING, filename STRING,

 imageinput STRING,hostname STRING,

macaddress STRING, 

`end` STRING, te STRING, systemtime STRING,

cpu BIGINT, diskusage STRING, 

memory BIGINT, 

id STRING,

PRIMARY KEY (uuid)

)

PARTITION BY HASH PARTITIONS 16 

STORED AS KUDU 
  

TBLPROPERTIES ('kudu.num\_tablet\_replicas' = '1');
  

### 

### References

- [https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.2/org.apache.nifi.processors.standard.ListDatabaseTables/index.html](https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.2/org.apache.nifi.processors.standard.ListDatabaseTables/index.html)
- [https://www.marklogic.com/blog/apache-nifi-ingest-relational-data-to-marklogic/](https://www.marklogic.com/blog/apache-nifi-ingest-relational-data-to-marklogic/)
- [https://www.batchiq.com/database-extract-with-nifi.html](https://www.batchiq.com/database-extract-with-nifi.html)
- [https://blog.pythian.com/database-migration-using-apache-nifi/](https://blog.pythian.com/database-migration-using-apache-nifi/)
- [https://www.progress.com/blogs/tutorial-access-data-via-jdbc-with-apache-nifi](https://www.progress.com/blogs/tutorial-access-data-via-jdbc-with-apache-nifi)
- [https://marklogic.github.io/nifi/get-data-from-a-relational-database](https://marklogic.github.io/nifi/get-data-from-a-relational-database)
- [https://community.cloudera.com/t5/Community-Articles/ETL-With-Lookups-with-Apache-HBase-and-Apache-NiFi/ta-p/248243](https://community.cloudera.com/t5/Community-Articles/ETL-With-Lookups-with-Apache-HBase-and-Apache-NiFi/ta-p/248243)
- [https://community.cloudera.com/t5/Community-Articles/Ingesting-RDBMS-Data-As-New-Tables-Arrive-Automagically-into/ta-p/246214](https://community.cloudera.com/t5/Community-Articles/Ingesting-RDBMS-Data-As-New-Tables-Arrive-Automagically-into/ta-p/246214)
- [https://community.cloudera.com/t5/Community-Articles/QADCDC-Our-how-to-ingest-some-database-tables-to-Hadoop-Very/ta-p/245229](https://community.cloudera.com/t5/Community-Articles/QADCDC-Our-how-to-ingest-some-database-tables-to-Hadoop-Very/ta-p/245229)
- [https://community.cloudera.com/t5/Community-Articles/Exporting-and-Importing-Data-from-MongoDB-in-the-Cloud-with/ta-p/249470 ](https://community.cloudera.com/t5/Community-Articles/Exporting-and-Importing-Data-from-MongoDB-in-the-Cloud-with/ta-p/249470%C2%A0)
- [https://community.cloudera.com/t5/Community-Articles/Easy-Hadoop-Backup/ta-p/245843](https://community.cloudera.com/t5/Community-Articles/Easy-Hadoop-Backup/ta-p/245843)
- [https://community.cloudera.com/t5/Community-Articles/Su-Su-Sussudio-Sudoers-Log-Parsing-with-Apache-NiFi/ta-p/249461](https://community.cloudera.com/t5/Community-Articles/Su-Su-Sussudio-Sudoers-Log-Parsing-with-Apache-NiFi/ta-p/249461)
- [https://community.cloudera.com/t5/Community-Articles/Ingesting-SQL-Server-Tables-into-Hive-via-Apache-NiFi-and/ta-p/244665](https://community.cloudera.com/t5/Community-Articles/Ingesting-SQL-Server-Tables-into-Hive-via-Apache-NiFi-and/ta-p/244665)
- [https://community.cloudera.com/t5/Community-Articles/Reading-Kerberos-KDC-Logs-and-Parsing-Them-for-Events-via/ta-p/249411](https://community.cloudera.com/t5/Community-Articles/Reading-Kerberos-KDC-Logs-and-Parsing-Them-for-Events-via/ta-p/249411)
- [https://community.cloudera.com/t5/Support-Questions/How-can-I-ingest-500-tables-automatically-in-Apache-Nifi/td-p/198397](https://community.cloudera.com/t5/Support-Questions/How-can-I-ingest-500-tables-automatically-in-Apache-Nifi/td-p/198397)
- [https://community.cloudera.com/t5/Community-Articles/Incrementally-Streaming-RDBMS-Data-to-Your-Hadoop-DataLake/ta-p/247927](https://community.cloudera.com/t5/Community-Articles/Incrementally-Streaming-RDBMS-Data-to-Your-Hadoop-DataLake/ta-p/247927)
- [https://community.cloudera.com/t5/Community-Articles/Apache-NiFi-Processor-Building-a-SQL-DDL-Schema-From-A-JSON/ta-p/247989](https://community.cloudera.com/t5/Community-Articles/Apache-NiFi-Processor-Building-a-SQL-DDL-Schema-From-A-JSON/ta-p/247989)
-