Apache Nifi 简明教程

Apache NiFi - Custom Processor

Apache NiFi 是一个开源平台,为开发者提供了在 NiFi 库中添加其定制处理器的选项。按照这些步骤创建自定义处理器。

Apache NiFi is an open source platform and gives developers the options to add their custom processor in the NiFi library. Follow these steps to create a custom processor.

  1. Download Maven latest version from the link given below. https://maven.apache.org/download.cgi

  2. Add an environment variable named M2_HOME and set value as the installation directory of maven.

  3. Download Eclipse IDE from the below link. https://www.eclipse.org/downloads/download.php

  4. Open command prompt and execute Maven Archetype command.

> mvn archetype:generate
  1. Search for the nifi type in the archetype projects.

  2. Select org.apache.nifi:nifi-processor-bundle-archetype project.

  3. Then from the list of versions select the latest version i.e. 1.7.1 for this tutorial.

  4. Enter the groupId, artifactId, version, package, and artifactBaseName etc.

  5. Then a maven project will be created having to directories. nifi-<artifactBaseName>-processors nifi-<artifactBaseName>-nar

  6. Run the below command in nifi-<artifactBaseName>-processors directory to add the project in the eclipse.

mvn install eclipse:eclipse
  1. Open eclipse and select import from the file menu.

  2. Then select “Existing Projects into workspace” and add the project from nifi-<artifactBaseName>-processors directory in eclipse.

  3. Add your code in public void onTrigger(ProcessContext context, ProcessSession session) function, which runs when ever a processor is scheduled to run.

  4. Then package the code to a NAR file by running the below mentioned command.

mvn clean install
  1. A NAR file will be created at nifi- -nar/target directory.

  2. Copy the NAR file to the lib folder of Apache NiFi and restart the NiFi.

  3. After successful restart of NiFi, check the processor list for the new custom processor.

  4. For any errors, check ./logs/nifi.log file.