Apache Nifi 简明教程

Apache NiFi - Creating Flows

Apache NiFi 提供大量组件,帮助开发人员为任何类型的协议或数据源创建数据流。若要创建流,开发人员可将组件从菜单栏拖动至画布,然后单击并拖动鼠标,将组件彼此连接。

Apache NiFi offers a large number of components to help developers to create data flows for any type of protocols or data sources. To create a flow, a developer drags the components from menu bar to canvas and connects them by clicking and dragging the mouse from one component to other.

通常,NiFi 在流的开始部分有类似 getfile 的侦听器组件,用于从源系统获取数据。在另一端有类似 putfile 的发送器组件,以及处理数据的中间组件。

Generally, a NiFi has a listener component at the starting of the flow like getfile, which gets the data from source system. On the other end of there is a transmitter component like putfile and there are components in between, which process the data.

例如,让我们创建一个流,该流从一个目录中获取一个空文件,然后在该文件中添加一些文本,并将它放入另一个目录中。

For example, let create a flow, which takes an empty file from one directory and add some text in that file and put it in another directory.

creating flow
  1. To begin with, drag the processor icon to the NiFi canvas and select GetFile processor from the list.

  2. Create an input directory like c:\inputdir.

  3. Right-click on the processor and select configure and in properties tab add Input Directory (c:\inputdir) and click apply and go back to canvas.

  4. Drag the processor icon to the canvas and select the ReplaceText processor from the list.

  5. Right-click on the processor and select configure. In the properties tab, add some text like “Hello tutorialspoint.com” in the textbox of Replacement Value and click apply.

  6. Go to settings tab, check the failure checkbox at right hand side, and then go back to the canvas.

  7. Connect GetFIle processor to ReplaceText on success relationship.

  8. Drag the processor icon to the canvas and select the PutFile processor from the list.

  9. Create an output directory like c:\outputdir.

  10. Right-click on the processor and select configure. In the properties tab, add Directory (c:\outputdir) and click apply and go back to canvas.

  11. Go to settings tab and check the failure and success checkbox at right hand side and then go back to the canvas.

  12. Connect the ReplaceText processor to PutFile on success relationship.

  13. Now start the flow and add an empty file in input directory and you will see that, it will move to output directory and the text will be added to the file.

通过遵循以上步骤,开发人员可以选择任何处理器和其他 NiFi 组件,为他们的组织或客户创建合适的流程。

By following the above steps, developers can choose any processor and other NiFi component to create suitable flow for their organisation or client.