首页 > 解决方案 > Kafka Sink 如何将字段映射到具有不同主题和表模式名称的数据库

问题描述

我目前正在使用主题名称设置 Kafka Sink 连接器waiting-room,同时调用我的 db 架构waiting_room。所以我试图将主题消息映射到数据库模式,但我没有看到任何数据进入数据库。所以我尝试了以下场景:

  1. 因此,由于表模式是waiting_room我尝试添加的quote.sql.identifier=ALWAYS,因为它引用了表名并允许 Kafka 接收器引用它,因此它可以映射到表,但我在 Kafka 接收器中没有看到quote.sql.identifier=ALWAYS。table.schema 和 Kafka 接收器是否都需要引用才能映射它,或者我如何将表模式映射为下划线并让 kafka 映射它
  2. 然后,如果我更改了table.name.format=waiting-roomdb schema = gt.namespace."waiting-room" 我没有看到我的 kafka sink 得到更新,而是我的 table.name.format 将 = waiting_room 并且连接器的状态为 404 不成立。

当主题和数据库名称不同时,有没有办法映射并将数据输入数据库

标签: postgresqljdbcapache-kafkaapache-kafka-connectconfluent-schema-registry

解决方案


尝试使用 Kafka Connect SMT RegexRouter

{
    "task.max": "1",
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "connection.url": "'"$URL"'",
    "topics": "waiting-room",

    "transforms": "route",
    "transforms.route.type": "org.apache.kafka.connect.transforms.RegexRouter",
    "transforms.route.regex": "waiting-room",
    "transforms.route.replacement": "gt.namespace.waiting_room",

    "errors.tolerance": "all",
    "errors.log.enable": "true",
    "errors.log.include.messages": true
}

推荐阅读