0

我正在尝试学习如何创建自定义 NiFi 控制器服务。一开始,我想DBCPConnectionPool通过简单地复制服务的原始源代码来模仿控制器DBCPConnectionPool服务。为了实现同样的功能,我从“nifi- service -bundle-archetype”生成了一个 maven 原型,并得到了以下项目结构 在此处输入图像描述

但是,当我从 'nifi - processor -bundle -archetype 生成原型时,我得到了以下结构: - 在此处输入图像描述

我知道在处理器的情况下,我只需要在MyProceesor.java当前nifi-ListDbTableDemo-processors文件夹下编写我的代码,然后从中创建一个 nar 文件。但在控制器服务的情况下,我生成了 4 个文件夹。我可以看到两个java文件,即

  1. StandardMyService.java出现在nifi-DbcpServiceDemo文件夹下

  2. MyService.java出现在nifi-DbcpServiceDemo-api文件夹下

现在,为什么在自定义控制器服务的情况下会生成两个java文件,而在自定义处理器的情况下只生成一个java文件。另外,由于我试图模仿DBCPConnectionPool服务,我应该在其中的两个 java 文件中复制服务的原始源代码DBCPConnectionPool

请从头开始指导我,创建与服务等效的自定义服务需要遵循的步骤DBCPConnectionPool

4

1 回答 1

7

MyService.javaunder是一个由undernifi-DbcpServiceDemo-api实现的接口。实现完成后,您必须在需要与此自定义控制器服务一起使用的处理器包中用作依赖项。StandardMyService.javanifi-DbcpServiceDemonifi-DbcpServiceDemo-api

控制器服务之所以这样实现的原因是:

  • 我们将从处理器包中隐藏实际的实现,因为它不需要依赖于实现。
  • 明天你编写一个新的控制器服务实现,再说说StandardMyServiceTwo哪个实现,MyService因为只有实现不同StandardMyService,其他成员保持不变并且可以共享。这种新的控制器服务可以透明地引入,而无需对处理器包进行任何更改。

例子:

The best example is the record reader/writer controller services. If you look at the nifi-record-serialization-services-bundle in nifi, they have different implementation for serializing records of JSON, Grok, avro, CSV data formats but they all are actually implementing one API - nifi-record-serialization-service-api And hence for the processors which want to use the Record Reader or Record Writer, instead of having the actual implementations as its dependency, they rather can have the api as its dependency.

So tomorrow you can add add a new implementation in the record-serialization-services-bundle for a new data format without touching anything on the processors bundle.

供您参考,请查看以下链接,这些链接将帮助您从头开始编写自定义控制器服务

于 2018-04-17T09:41:13.183 回答