HeaderToValue
示例
要将事件记录中的消息头提取到记录值中,请在连接器的 Kafka Connect 配置中配置 HeaderToValue SMT。您可以配置转换以移除原始头或复制它们。要从记录中移除头字段,请将 SMT 配置为使用 move 操作。要保留原始记录中的头字段,请将 SMT 配置为使用 copy 操作。例如,要从事件消息中移除 event_timestamp 和 key 头,请将以下行添加到您的连接器配置中:
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
以下示例显示了在应用转换之前和之后的事件记录的头和值。
示例 1. 应用
HeaderToValue SMT 的效果HeaderToValue转换处理之前的事件记录-
- SMT 处理事件记录之前的头
-
{ "header_x": 0, "event_timestamp": 1626102708861, "key": 100, } - SMT 处理事件记录之前的值
-
{ "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, "ts_us": 1559033904863091, "ts_ns": 1559033904863091000, "snapshot": true, "db": "postgres", "sequence": "[\"24023119\",\"24023128\"]" "schema": "public", "table": "customers", "txId": 555, "lsn": 24023128, "xmin": null }, "op": "c", "ts_ms": 1559033904863, "ts_us": 1559033904863741, "ts_ns": 1559033904863741697 }
HeaderToValue转换处理之后的事件记录-
- SMT 移除指定字段之后的头
-
{ "header_x": 0 } - SMT 将头字段移入值之后的记录值
-
{ "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, "ts_us": 1559033904863697, "ts_ns": 1559033904863697000, "snapshot": true, "db": "postgres", "sequence": "[\"24023119\",\"24023128\"]" "schema": "public", "table": "customers", "txId": 555, "lsn": 24023128, "xmin": null, "id": 100 }, "op": "c", "ts_ms": 1559033904863, "ts_us": 1559033904863631, "ts_ns": 1559033904863631584, "event_timestamp": 1626102708861 }
配置选项
下表列出了您可以在 HeaderToValue SMT 中使用的配置选项。
属性 |
描述 |
Type |
Default (默认值) |
有效值 |
重要性 |
记录中要复制或移动到记录值的头名称的逗号分隔列表。 |
列表 |
无默认值 |
非空列表 |
高 |
|
字段名称的逗号分隔列表,顺序与 |
列表 |
无默认值 |
非空列表 |
高 |
|
指定以下选项之一: |
string |
无默认值 |
move 或 copy |
高 |