Create a custom NiFi processor by extending the default Ingest processor in the NiFi Toolkit
In this topic, you will learn to create a custom NiFi processor by extending the default Ingest processor in the NiFi Toolkit.
Procedure
- Extract commerce-custom-search-marketplace-seller.zip to a working directory, commerce-custom-search-marketplace-seller, that contains a Maven project with a pom.xml file inside it.
- Copy the following JAR files obtained from the NiFi container to the
commerce-custom-search-marketplace-seller/libs
project directory that was extracted from the project
commerce-custom-search-marketplace-seller.zip.
For more information, refer to steps 3
through 6
of Custom NiFi
processors.
Example from V9.1.10.0:
- commerce-search-processors-9.1.10.0.jar
- hcl-cache-core-9.1.10.0-20220322.160926-24.jar
- cf-base-9.1.10.0-20220322.160733-7.jar
ingest-api.jar, which was included in the commerce-custom-search-marketplace-seller.zip project template, is already present in this folder.Note: From V9.1.12.0 onwards, ingest-api.jar is not made available inside tutorial assets. - Update pom.xml file in the root directory of the
commerce-custom-search-marketplace-seller
project and change the file name references to the JAR file
names.Example from V9.1.10.0:
<dependency> <groupId>com.hcl.commerce</groupId> <artifactId>dummy-commerce-search-processors</artifactId> <version>9.1.10.0</version> <scope>system</scope> <systemPath>${project.basedir}/libs/commerce-search-processors-9.1.10.0.jar</systemPath> </dependency> <dependency> <groupId>com.hcl.commerce</groupId> <artifactId>dummy-hcl-cache-core</artifactId> <version>9.1.10.0</version> <scope>system</scope> <systemPath> ${project.basedir}/libs/hcl-cache-core-9.1.10.0-20220322.160926-24.jar</systemPath> </dependency> <dependency> <groupId>com.ibm.commerce.cf</groupId> <artifactId>dummy-cf-base</artifactId> <version>9.1.10.0</version> <scope>system</scope> <systemPath> ${project.basedir}/libs/cf-base-9.1.10.0-20220322.160733-7.jar</systemPath> </dependency>
- Import the extracted project as a Maven project into eclipse (commerce-custom-search-marketplace-seller.
Click Finish. Wait for the dependencies to
complete downloading.
This project has an example custom expression provider class ChangeSQL which implements the IngestExpressionProviderinterface. The ChangeSQL class extends the SQL to include a “DESCRIPTION” column from the SELLERDESC table. You can use this sample reference to learn how to modify the SQL used in the default Extract, Transform, and Load (ETL) stages.
ComposeDatabaseSQLTest is the JUnit test that can be used for verifying the code logic of ChangeSQL.
ChangeDocument is an Ingest profile post-processor extension that demonstrates how you can perform further data manipulation following the default transformation, in one of the Product related Ingest stages. CreateProductDocumentFromDatabaseTest is the JUnit test that can be used to verify the code logic inside of ChangeDocument. In this class, add an additional field “seller_description” with the value from the “DESCRIPTION” column of the MPSELLERDESC table into the document that is to be indexed in the Elasticsearch.
In the Project explorer, Right-click project Maven build and Maven build... select Maven build...) The Edit Configuration window opens.
(Note that there are two menu items,Enter the command clean install -U -Denforcer.skip=true into the Goals textbox and click the Run button.
Once the build is finished, the jar file will be available in the target directory of this project, for example: commerce-custom-search-marketplace-seller-9.1.x.0.jar. For more information, see Custom NiFi processors.
) and select the root directory
In this topic, you have created a custom NiFi processor by extending the default Ingest processor using the NiFi Toolkit. In the next section, you will test the custom ingest logic in NiFi Toolkit before it can be deployed on the development or production environment.
Testing custom ingest logic in NiFi toolkit and building deployable JAR
In this topic, you will test the custom NiFi processor logic created in NiFi Toolkit before it can be deployed on the production environment.
Procedure
To run the JUnit test, right-click on the chosen JUnit Test class and choose either
or .- Update projects by right-clicking on the Project and select .
- Select OK button. Rebuild
the binaries for project
commerce-custom-search-bundles-9.1.10.0.Note:
- The commerce-custom-search-marketplace-seller customization project does not have any dependencies on the commerce-custom-search-bundles-9.1.x.x project, however it is recommended that you build the commerce-custom-search-bundles-9.1.x.x project before proceeding with any customizations. This can be useful for other customizations that may have dependencies on the commerce-custom-search-bundles-9.1.x.x for other use-cases.
- If you
encounter any missing dependencies for
dummy-commerce-search-processors
,dummy-hcl-cache-core
ordummy-cf-base
JAR files, see Troubleshooting: Missing custom NiFi processor dependencies.
Build the binaries for the project commerce-custom-search-marketplace-seller:
Initiate a Maven Build... on the root bundle project. In the Project Explorer, right-click on the root (commerce-search-custom-bundle-9.1.x.x) and select . The Edit Configuration window opens.
Enter the following command nto the Goals entry field:
Click the Run button.clean install -U -Denforcer.skip=true
Once the build is successful, the JAR files can be viewed in the target subdirectory of the
commerce-custom-search-processors
project. For more information, see Custom NiFi processors.
and click
The NiFi Toolkit's unique NiFi processor logic has been explored in this topic. Ingest logic can now be customized and deployed in production environments.