【问题标题】:Kafka Connect and Debezium MySQL source - How do you get rid of Struct{} in the message Key?Kafka Connect 和 Debezium MySQL 源码 - 如何去掉消息 Key 中的 Struct{}?
【发布时间】:2021-10-10 16:41:46
【问题描述】:

debezium MySQL 连接器生成的 Kafka 消息密钥类似于 Struct{id=1} 而不是 1。

我的配置如下:

connector.class=io.debezium.connector.mysql.MySqlConnector
name=mysql-source
database.server.name=dbserver1
tasks.max=1
database.hostname=127.0.0.1
database.port=3306
database.user=root
database.password=*****
database.server.id=1
topic.creation.enable=true
topic.creation.default.replication.factor=-1
topic.creation.default.partitions=1
database.history.kafka.bootstrap.servers=*****
database.history.kafka.topic=dbserver1-schema-history
database.history.consumer.security.protocol=SASL_SSL
database.history.consumer.sasl.mechanism=PLAIN
database.history.consumer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="JM6MDWHYK4SKMDX6" password="Vvah2zS6bDaYAUYgYiod/iatMtEjC6vnwIuNM847JdwH+M+SSQzhxsTSI+GnjY5z";
database.history.producer.security.protocol=SASL_SSL
database.history.producer.sasl.mechanism=PLAIN
database.history.producer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="****" password="****";

并添加

transforms=flatten
transforms.flatten.type=org.apache.kafka.connect.transforms.Flatten$Key

不起作用。

那么就是sink期间delete方式的问题,因为目标数据库的主键列如下:

|id          |
---------------
|Struct{id=x}|

有什么帮助吗?

【问题讨论】:

    标签: apache-kafka apache-kafka-connect


    【解决方案1】:

    Flatten 变换将嵌套的 Struct 转换为扁平结构。你好像在找ExtractField$Key...

    或者,使用 value.converter 的 JSON/Avro/Protobuf 选项而不是 StringConverter 来删除 Struct.toString() 表示。

    这也会将键值对提取到与您的接收器连接器兼容的数据中

    【讨论】:

    • 我在 Kafka 连接器的 Source & Sink 两侧使用 value.converter=org.apache.kafka.connect.json.JsonConverter 解决了这个问题。
    • @felicienb 很高兴听到。随意使用帖子旁边的复选标记接受答案
    猜你喜欢
    • 2019-10-19
    • 2018-11-23
    • 1970-01-01
    • 2020-07-09
    • 2021-07-14
    • 2021-07-13
    • 2022-01-10
    • 2020-10-08
    • 1970-01-01
    相关资源
    最近更新 更多