简体   繁体   English

如何使用kafka connect jdbc sink将kafka主题连接到postgres数据库

[英]how to connect kafka topics to postgres database using kafka connect jdbc sink

got errors while trying to connect kafka topics to postgres using jdbcsink connector尝试使用 jdbcsink 连接器将 kafka 主题连接到 postgres 时出错

these are the error logs(see image) that i got when tried with the configuration这些是我在尝试配置时得到的错误日志(见图)

{
    "name": "temperature_jdbcsink",

    "config" : {

    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "task.max": "1",
    "topics": "temperature",

    "key.converter": "io.confluent.connect.avro.AvroConverter",
    "value.converter": "io.confluent.connect.avro.AvroConverter",   
    "key.converter.schema.registry.url": "http://localhost:8081", 
    "value.converter.schema.registry.url": "http://localhost:8081",
    
    "transforms": "Flatten, RenameFields",
    "transfores.Flatten.type":"org.apache.kafka.connect.transforms.Flatten$value",
    "transforms.Flatten.deliniter":"_",
    
    "transforms.RenameFields.type": "org.apache.kafka.connect.transforms.ReplaceField$value",
    "transforms.RenameFields.renames": "value:value,timestamp:timestamp",
    
    "connection.url": "jdbc:postgresql://localhost:5432/jdbcsink",
    "connection.user": "postgres",
    "connection.password": "postgres",
    "insert.mode": "upsert",
    "batch.size":"2",
    "table.name.format": "temperature",
    "pk.mode":"none",
    "db.timezone": "Asia/Kolkata"
    }
}

https://i.stack.imgur.com/fXqO3.png https://i.stack.imgur.com/fXqO3.png
https://i.stack.imgur.com/fXqO3.png https://i.stack.imgur.com/fXqO3.png
https://i.stack.imgur.com/V5Btk.png https://i.stack.imgur.com/V5Btk.png

Error says Unknown magic byte .错误说Unknown magic byte This seems there is data in the topic that wasn't produced using Confluent Avro serializer主题中似乎有数据不是使用 Confluent Avro 序列化程序生成的

For example, are your keys really Avro?例如,您的密钥真的是 Avro 吗? This isn't common for storing data in JDBC sink since database primary keys are typically plain string or integer types.这对于在 JDBC 接收器中存储数据并不常见,因为数据库主键通常是纯字符串或整数类型。 Therefore, use the respective converter for those, not Avro因此,使用相应的转换器,而不是 Avro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM