Debezium-自定义有效负载-MySQL Connector

时间:2019-12-17 18:48:33

标签: mysql apache-kafka apache-kafka-connect debezium

我使用Debezium将数据从MySQL同步到S3。现在我要进行一些更改。

示例插入:

create table new (id int);
insert into new (1);

1。自定义有效载荷

{
    "schema": {
        "type": "struct",
        bla bla bla
        "optional": false,
        "name": "_72.31.84.129.test.new.Envelope"
    },
    "payload": {
        "before": null,
        "after": {
            "id": 10
        },
        "source": {
            "version": "0.10.0.Final",
            "connector": "mysql",
            "name": "11.11.84.129",
            "ts_ms": 1576605998000,
            "snapshot": "false",
            "db": "test",
            "table": "new",
            "server_id": 1,
            "gtid": "3a7b90e9-207e-11ea-b3ed-121a0cbac3cb:51",
            "file": "mysql-bin.000003",
            "pos": 12770,
            "row": 0,
            "thread": 47,
            "query": null
        },
        "op": "c",
        "ts_ms": 1576605998231
    }
}

我只想通过一些自定义更改来推送有效负载选项。我需要将source,op,ts_ms包含在payload.after内。

预期输出:

{
            "id": 10, 
            "source": {
            "version": "0.10.0.Final",
            "connector": "mysql",
            "name": "11.11.84.129",
            "ts_ms": 1576605998000,
            "snapshot": "false",
            "db": "test",
            "table": "new",
            "server_id": 1,
            "gtid": "3a7b90e9-207e-11ea-b3ed-121a0cbac3cb:51",
            "file": "mysql-bin.000003",
            "pos": 12770,
            "row": 0,
            "thread": 47,
            "query": null
        },
        "op": "c",
        "ts_ms": 1576605998231
        }

我不需要模式,payload.before。我不确定如何获得此输出。

1 个答案:

答案 0 :(得分:0)

签出SMT以提取新记录状态。它只会传播after中的内容。 (可选)您也可以让它添加source中的选定字段。

...
transforms=unwrap
transforms.unwrap.type=io.debezium.transforms.ExtractNewRecordState
transforms.unwrap.add.source.fields=table,lsn
...

您不能插入opts_ms域atm。,但可以将它们传播为消息标题。