【发布时间】:2019-08-17 12:44:29
【问题描述】:
我有一个 Kafka 主题,其中包含带有 Avro 序列化键和 Avro 序列化值的消息。
我正在尝试设置一个接收器连接器以将这些值放入 postgres 数据库(在本例中为 AWS RDS)中的表中。
我已经尝试了许多关于主题、消息和接收器配置本身的变体,但是看看下面的例子,如果有人可以提供关于我哪里出错的指导,那就太好了! :)
我的主题具有以下架构(在架构注册表中)...
密钥架构
{
"type": "record",
"name": "TestTopicKey",
"namespace": "test.messaging.avro",
"doc": "Test key schema.",
"fields": [
{
"name": "unitId",
"type": "int"
}
]
}
值模式
{
"type": "record",
"name": "TestTopicValues",
"namespace": "test.messaging.avro",
"doc": "Test value schema.",
"fields": [
{
"name": "unitPrice",
"type": "int",
"doc": "Price in AUD excluding GST."
},
{
"name": "unitDescription",
"type": "string"
}
]
}
我正在使用“kafka-avro-console-producer”手动生成主题记录,如下所示:
/bin/kafka-avro-console-producer --broker-list kafka-box-one:9092 --topic test.units --property parse.key=true --property "key.separator=|" --property "schema.registry.url=http://kafka-box-one:8081" --property key.schema='{"type":"record","name":"TestTopicKey","namespace":"test.messaging.avro","doc":"Test key schema.","fields":[{"name":"unitId","type":"int"}]}' --property value.schema='{"type":"record","name":"TestTopicValues","namespace":"test.messaging.avro","doc":"Test value schema.","fields":[{"name":"unitPrice","type":"int","doc":"Price in AUD excluding GST."},{"name":"unitDescription","type":"string"}]}'
一旦 Producer 启动,我就可以成功地将记录添加到主题,如下所示:
{"unitId":111}|{"unitPrice":15600,"unitDescription":"A large widget thingy."}
注意:我也可以按预期成功使用 kafka-avro-console-consumer 消费。
我试图沉入的 postgres 表如下所示:
CREATE TABLE test_area.unit_prices (
unitId int4 NOT NULL,
unitPrice int4 NULL,
unitDescription text NULL,
CONSTRAINT unit_prices_unitid_pk PRIMARY KEY (unitId)
);
我的接收器连接器如下所示:
{
"name": "test.area.unit.prices.v01",
"config": {
"connector.class": "JdbcSinkConnector",
"topics": "test.units",
"group.id": "test.area.unit.prices.v01",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "http://kafka-box-one:8081",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "http://kafka-box-one:8081",
"connection.user": "KafkaSinkUser",
"connection.password": "KafkaSinkPassword",
"connection.url": "jdbc:postgresql://unit-catalogue.abcdefghij.my-region-1.rds.amazonaws.com:5432/unit_sales?currentSchema=test_area",
"table.name.format": "unit_prices",
"auto.create": false,
"auto.evole": "false"
}
}
我的期望是记录会在 Sink 显示为正在运行后不久出现在 postgres 表中。然而,什么都没有下沉。
补充说明:
- 我可以通过使用 usql 的 Sink 连接器使用凭据发布此 Sink 连接器的 Kafka Connect 框连接和写入 postgres RDS 实例。
- 接收器连接器状态为“正在运行”,这表明接收器语法中没有错误。
【问题讨论】:
-
检查您的 Kafka Connect 工作日志。那里有任何错误或警告吗?
-
感谢罗宾,为迟来的回复道歉。我在让我的日志记录工作时遇到问题,所以一直在盲目工作。但是通过一些谷歌搜索发现我认为它们需要在我的 log4j 属性中进行配置。一旦我得到一些日志工作,我会再次回复。请继续关注 :) 与此同时,如果您或其他人发现我的上述设置有任何问题,请同时尝试建议。
-
您如何运行 Kafka Connect 工作程序?如果只是从命令行,那么日志会直接发送到控制台 (
stdout) -
在运行我的 Kafka 连接器的主机上,我正在使用 cURL 命令提交我的 Kafka Connect 作业。例如: curl -X POST -H "Content-Type: application/json" --data @${mySinkJsonFile} localhost:8083/connectors(Kafka 主题本身在另一台主机上)我得到的唯一反馈是 cURL 通信时间等统计信息。
-
那是 configuring Kafka Connect - 当您 run Kafka Connect 本身时,您从命令行启动工作程序(或者可能从
confluent start运行它?还是系统服务?)
标签: apache-kafka avro apache-kafka-connect confluent-schema-registry