HeaderToValue
Example
To extract message headers in an event record into the record value, configure the HeaderToValue
SMT in the Kafka Connect configuration for a connector. You can configure the transformation to either remove the original headers or to copy them. To remove header fields from the record, configure the SMT to use the move
operations. To retain the header fields in the original record, configure the SMT to use the copy
operation. For example, to remove the headers event_timestamp
and key
from an event message, add the following lines to your connector configuration:
transforms=moveHeadersToValue
transforms.moveHeadersToValue.type=io.debezium.transforms.HeaderToValue
transforms.moveHeadersToValue.headers=event_timestamp,key
transforms.moveHeadersToValue.fields=timestamp,source.id
transforms.moveHeadersToValue.operation=move
The following example shows the headers and values of an event record before and after the transformation is applied.
Example 1. Effect of applying the HeaderToValue
SMT
Event record before it is processed by the HeaderToValue
transformation
Header before the SMT processes the event record
{
"header_x": 0,
"event_timestamp": 1626102708861,
"key": 100,
}
Value before the SMT processes the event record
{
"before": null,
"after": {
"id": 1,
"first_name": "Anne",
"last_name": "Kretchmar",
"email": "annek@noanswer.org"
},
"source": {
"version": "2.1.3.Final",
"connector": "postgresql",
"name": "PostgreSQL_server",
"ts_ms": 1559033904863,
"snapshot": true,
"db": "postgres",
"sequence": "[\"24023119\",\"24023128\"]"
"schema": "public",
"table": "customers",
"txId": 555,
"lsn": 24023128,
"xmin": null
},
"op": "c",
"ts_ms": 1559033904863
}
Event record after it is processed by the HeaderToValue
transformation
Header after the SMT removes the specified field
{
"header_x": 0
}
Value after the SMT moves header fields into the value
{
"before": null,
"after": {
"id": 1,
"first_name": "Anne",
"last_name": "Kretchmar",
"email": "annek@noanswer.org"
},
"source": {
"version": "2.1.3.Final",
"connector": "postgresql",
"name": "PostgreSQL_server",
"ts_ms": 1559033904863,
"snapshot": true,
"db": "postgres",
"sequence": "[\"24023119\",\"24023128\"]"
"schema": "public",
"table": "customers",
"txId": 555,
"lsn": 24023128,
"xmin": null,
"id": 100
},
"op": "c",
"ts_ms": 1559033904863,
"event_timestamp": 1626102708861
}
Configuration options
The following table lists the configuration options that you can use with the HeaderToValue
SMT.
Property | Description | Type | Default | Valid Values | Importance |
A comma-separated list of header names in the record whose values are to be copied or moved to the record value. | list | No default value | non-empty list | high | |
A comma-separated list of field names, in the same order as the header names listed in the | list | No default value | non-empty list | high | |
Specifies one of the following options: | string | No default value | move or copy | high |