Skip to main content

Kafka Connect Single Message Transforms (SMTs)

Single Message Transforms (SMTs) are lightweight per-record transformations applied inside Kafka Connect, either before a source connector writes to Kafka or before a sink connector writes to the external system. They are best for lightweight record changes, not complex joins, filtering, or business logic.

Key Points​

  • Use the $Key suffix to transform the record key and $Value to transform the record value (e.g. ReplaceField$Value).
  • Multiple SMTs can be chained via transforms=a,b,c; they run in the listed order.
  • Each transform is configured as transforms.<name>.type plus its own properties.

Built-in SMTs​

SMTPurpose
InsertFieldAdd a static, topic, partition, offset, or timestamp field
ReplaceFieldInclude, exclude, or rename fields
MaskFieldReplace sensitive fields with default values
ExtractFieldExtract one field from a structured record
ValueToKeyCopy value fields into the record key
HoistFieldWrap the entire key/value inside one field
FlattenFlatten nested structures
CastConvert field data types
TimestampConverterConvert timestamp formats or types
SetSchemaMetadataSet or change schema name/version
RegexRouterRename topics using a regular expression
TimestampRouterRoute records to time-based topic names
InsertHeaderAdd a header to the Kafka record
HeaderFromCopy fields to or from record headers

HoistField​

HoistField wraps the entire record key or value inside a named field. Use it when a connector or downstream system requires the record value to be a structured object. It wraps the whole value; it does not add a field to an existing object.

Input value:

"hello"

Configuration:

transforms=Hoist
transforms.Hoist.type=org.apache.kafka.connect.transforms.HoistField$Value
transforms.Hoist.field=payload

Output value:

{
"payload": "hello"
}

To wrap the key instead, use org.apache.kafka.connect.transforms.HoistField$Key.

Example: ReplaceField​

Rename and remove fields:

transforms=Replace
transforms.Replace.type=org.apache.kafka.connect.transforms.ReplaceField$Value
transforms.Replace.renames=old_name:new_name
transforms.Replace.exclude=internal_field