apacheminifyapache-nifihortonworks-data-platformhortonworks-dataflow

How to create a custom NiFi Controller Service?


I am trying to learn, how to create a custom NiFi controller service. To start off, I thought of mimicking the DBCPConnectionPool controller service by simply copying the original source code of DBCPConnectionPool service. To implement the same, I generated a maven archetype from "nifi-service-bundle-archetype" and got the following project structure enter image description here

However, when i generated the archetype from 'nifi-processor-bundle-archetype , I got the following structure: - enter image description here

I understand that in case of processor I simply need to write my code in MyProceesor.java present under nifi-ListDbTableDemo-processors folder and then create a nar file out of it. But in case of controller service, I have 4 folders generated. I can see two java files i.e.

  1. StandardMyService.java present under nifi-DbcpServiceDemo folder

  2. MyService.java present under nifi-DbcpServiceDemo-apifolder

Now, why is there two java files generated in case of custom controller service, while there was only one java file generated in case of custom processor. Also, Since I am trying to mimick the DBCPConnectionPool service, in which java file out of two should I copy the original source code of DBCPConnectionPool service.

Please guide me from scratch, the steps that I need to follow to create a custom service equivalent to that of DBCPConnectionPool service.


Solution

  • MyService.java under nifi-DbcpServiceDemo-api is an interface which be implemented by the StandardMyService.java under nifi-DbcpServiceDemo. Once the implementation is done, you have to use nifi-DbcpServiceDemo-api as dependency in the processor bundle which needs to work with this custom controller Service.

    The reason why controller services are implemented this way is:

    Example:

    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.

    For you references, please take a look at the following links which would help you in writing the custom controller service from scratch