简体   繁体   English

Kafka sink错误“此连接器要求Kafka中的记录包含Cassandra表的键”

[英]Kafka sink Error “This connector requires that records from Kafka contain the keys for the Cassandra table”

I am tring to sync all tables read from Sap into cassandra using kafka here is my cassandra config 我正在尝试使用kafka将所有从SAP读取的表同步到cassandra中,这是我的cassandra配置

{
    "name": "cassandra",
    "config": {
        "connector.class": "io.confluent.connect.cassandra.CassandraSinkConnector",
        "tasks.max": "5",
        "topics" :"sap_table1,sap_table2",
        "cassandra.keyspace": "sap",
        "cassandra.compression":"SNAPPY",
        "cassandra.consistency.level":"LOCAL_QUORUM",
        "cassandra.write.mode":"Update",
        "transforms":"prune", 
       "transforms.prune.type":"org.apache.kafka.connect.transforms.ReplaceField$Value",
        "transforms.prune.whitelist":"CreatedAt,Id,Text,Source,Truncated",
        "transforms.ValueToKey.fields":"ROWTIME"

    }
}

I am getting this error 我收到此错误

Task threw an uncaught and unrecoverable exception. Task is being killed and will not recover until manually restarted. (org.apache.kafka.connect.runtime.WorkerSinkTask:584) org.apache.kafka.connect.errors.DataException: Record with a null key was encountered.  This connector requires that records from Kafka contain the keys for the Cassandra table. Please use a transformation like org.apache.kafka.connect.transforms.ValueToKey to create a key with the proper fields.

All tables generated from kafka sap connectior are without a key i dunno if this is the issue 如果这是问题,那么从kafka sap connectior生成的所有表都没有密钥我不知道

let me know if i am doing anything wring 让我知道我在做什么

thanks 谢谢

"ROWTIME" only exists as a KSQL concept. "ROWTIME"仅作为KSQL概念存在。 It's not actually a field within your value, so therefore the key is being set to null. 它实际上不是您值中的一个字段,因此将键设置为null。

Also, ValueToKey isn't listed in the transforms list, so that's not even being applied. 另外, ValueToKey不在transforms列表中列出,因此甚至没有应用。 You'll have to add "transforms.ValueToKey.type" as well. 您还必须添加"transforms.ValueToKey.type"

You'll have to use a different transform method to set the record timestamp as the ConnectRecord message key 您必须使用其他转换方法来将记录时间戳记设置为ConnectRecord消息键

that error mean your data is not serialized so it is not in the json format or dictionary format {'key':'value'}. 该错误表示您的数据未序列化,因此不是json格式或字典格式{'key':'value'}。 if you read yoiur data directly from broker as a troubleshooting way you will find your data have only the values without any keys: 如果您直接从代理读取您的数据作为故障排除方法,您会发现您的数据仅包含没有任何键的值:

use this command to read your data from broker: 使用此命令从代理读取数据:

/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic your_topic_name--from-beginning

so the best way to solve this issue is to add serializer into your publisher configuration file. 因此,解决此问题的最佳方法是将序列化器添加到发布者配置文件中。 try this file as a source connector or publisher 尝试将此文件作为源连接器或发布者

name=src-view
connector.class=io.confluent.connect.jdbc.JdbcSourceConnector
tasks.max=1
topic.prefix=test-
connection.url=jdbc:postgresql://127.0.0.1:5434/test?user=testuser&password=testpass
mode=incrementing
incrementing.column.name=id
table.types=table
table.whitelist=table_name
validate.non.null=false
batch.max.rows=10000
bootstrap.servers=localhost:9092

key.converter=org.apache.kafka.connect.json.JsonConverter
key.converter.schema.registry.url=http://localhost:8081
value.converter=org.apache.kafka.connect.json.JsonConverter
value.converter.schema.registry.url=http://localhost:8081

internal.key.converter=org.apache.kafka.connect.json.JsonConverter
internal.value.converter=org.apache.kafka.connect.json.JsonConverter
internal.key.converter.schemas.enable=false
internal.value.converter.schemas.enable=false

and below is the consumer (sink.conf) to de-serialize your data: 下面是使用方(sink.conf)对数据进行反序列化:

name=cas-dest
connector.class=io.confluent.connect.cassandra.CassandraSinkConnector
tasks.max=1
topics=your_topic_name
cassandra.contact.points=127.0.0.1
cassandra.port=9042
cassandra.keyspace=your_keyspace_name
cassandra.write.mode=Update
cassandra.keyspace.create.enabled=true
cassandra.table.manage.enabled=true
key.converter.schema.registry.url=http://localhost:8081
value.converter.schema.registry.url=http://localhost:8081
bootstrap.servers=localhost:9092
key.converter=org.apache.kafka.connect.json.JsonConverter
key.converter.schema.registry.url=http://localhost:8081
value.converter=org.apache.kafka.connect.json.JsonConverter
value.converter.schema.registry.url=http://localhost:8081
internal.key.converter=org.apache.kafka.connect.json.JsonConverter
internal.value.converter=org.apache.kafka.connect.json.JsonConverter
internal.key.converter.schemas.enable=false
internal.value.converter.schemas.enable=false
transforms=createKey
transforms.createKey.fields=id,timestamp
transforms.createKey.type=org.apache.kafka.connect.transforms.ValueToKey

change the createKey.fields as per your data and be careful as it will be your partition keys so read about data modeling in cassandra before choosing your keys and it should be exist in your data key. 根据您的数据更改createKey.fields,并要小心,因为它将是您的分区键,因此在选择键之前,请先阅读cassandra中的数据建模,它应该存在于数据键中。

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

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