debezium-更改主题名称会导致错误的跨数据库引用

时间:2019-01-29 10:03:46

标签: apache-kafka apache-kafka-connect confluent confluent-schema-registry debezium

我正在使用此debezium-examples

source.json

{
"name": "inventory-connector",
"config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "tasks.max": "1",
    "database.hostname": "mysql",
    "database.port": "3306",
    "database.user": "debezium",
    "database.password": "dbz",
    "database.server.id": "184054",
    "database.server.name": "dbserver1",
    "database.whitelist": "inventory",
    "database.history.kafka.bootstrap.servers": "kafka:9092",
    "database.history.kafka.topic": "schema-changes.inventory",
    "transforms": "route",
    "transforms.route.type": "org.apache.kafka.connect.transforms.RegexRouter",
    "transforms.route.regex": "([^.]+)\\.([^.]+)\\.([^.]+)",
    "transforms.route.replacement": "$3"
}
}

jdbc-sink.json

{
"name": "jdbc-sink",
"config": {
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "tasks.max": "1",
    "topics": "customers",
    "connection.url": "jdbc:postgresql://postgres:5432/inventory?user=postgresuser&password=postgrespw",
    "transforms": "unwrap",
    "transforms.unwrap.type": "io.debezium.transforms.UnwrapFromEnvelope",
    "auto.create": "true",
    "insert.mode": "upsert",
    "pk.fields": "id",
    "pk.mode": "record_value"
}
}

我已经运行了这个示例,但是在下面的场景中进行了一些更改后,我进行了工作。它给了我“跨数据库引用”错误。

场景

我已从源代码中删除了这些属性

    "transforms": "route",
    "transforms.route.type": "org.apache.kafka.connect.transforms.RegexRouter",
    "transforms.route.regex": "([^.]+)\\.([^.]+)\\.([^.]+)",
    "transforms.route.replacement": "$3"

现在它在kafka中创建主题,如下所示

dbServer1.inventory.products

dbserver1.inventory.products_on_hand

dbserver1.inventory.customers

dbserver1.inventory.orders

当我在jdbc-sink中指定topic = dbserver1.inventory.customers时,它给了我以下 exception

 ERROR:  cross-database references are not implemented: 
"dbserver1.inventory.customers" at character 14
postgres_1   | STATEMENT:  CREATE TABLE "dbserver1"."inventory"."customers" (
postgres_1   |  "last_name" TEXT NOT NULL,
postgres_1   |  "id" INT NOT NULL,
postgres_1   |  "first_name" TEXT NOT NULL,
postgres_1   |  "email" TEXT NOT NULL,
postgres_1   |  PRIMARY KEY("id"))
connect_1    | 2019-01-29 09:39:18,931 WARN   ||  Create failed, will attempt amend if table already exists   [io.confluent.connect.jdbc.sink.DbStructure]
connect_1    | org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "dbserver1.inventory.customers"
connect_1    |   Position: 14

注意:它不是重复的,因为我也发布了其他问题,涵盖了不同的情况

2 个答案:

答案 0 :(得分:0)

更改库存-> dbserver1

(databasename).(schemaname).(tablename)

{
"name": "jdbc-sink",
"config": {
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "tasks.max": "1",
    "topics": "customers",
    "connection.url": "jdbc:postgresql://postgres:5432/dbserver1?user=postgresuser&password=postgrespw",
    "transforms": "unwrap",
    "transforms.unwrap.type": "io.debezium.transforms.UnwrapFromEnvelope",
    "auto.create": "true",
    "insert.mode": "upsert",
    "pk.fields": "id",
    "pk.mode": "record_value"
}
}

答案 1 :(得分:0)

table.name.format 接收器属性为我解决了这个问题。它允许您覆盖目标表名称。见https://docs.confluent.io/3.1.1/connect/connect-jdbc/docs/sink_config_options.html