If none of the available Single Message Transformations (SMTs) provide the
necessary transformation, you can create your own.
An important concept to understand first is that, generally, SMT implementations
provide the bulk of the logic in an abstract class. The SMT implementation then
provides two concrete subclasses called Key and Value that specify whether
to process the Connect record’s key or value. When using a transformation, users
specify the fully qualified class names of either the Key or Value class.
The following are the high-level steps necessary to create and use a custom SMT.
Review the different SMT source java files available from the default Kafka Connect transformations. Use one of these as a basis for creating your new custom transformation.
The following are important methods to note when reviewing the source java files:
Write and compile your source code and unit tests. Sample unit tests for SMTs can be found in the Apache Kafka GitHub project.
Create your JAR file.
Install the JAR file. Copy your custom SMT JAR file (and any non-Kafka JAR files required by the transformation) into a directory that is under one of the directories listed in the
plugin.path property in the Connect worker configuration file as shown below:
For example, create a directory named
/usr/local/share/kafka/plugins and copy the JAR files into the
Start up the workers and the connector, and then try out your custom transformation.
The Connect worker logs each transformation class it finds at the DEBUG level. Enable DEBUG mode and verify that your transformation was found. If not, check the JAR installation and make sure it’s in the correct location.