通过Kafka REST向Confluent Cloud主题发送AVRO消息时遇序列化错误
Kafka REST API发送AVRO消息到Confluent Cloud报错解决
错误信息
"message": "Cannot construct instance of
io.confluent.kafkarest.entities.v3.ProduceRequest$ProduceRequestData, problem: 'schema_version=17' cannot be used with 'serializer'."
原请求代码
curl --location 'https://{host}/kafka/v3/clusters/{cluster}/topics/{topic-name}/records' \ --header 'Confluent-Identity-Pool-Id: {pool-id}' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer jwt_token' \ --data '{ "partition_id": 0, "key": { "type": "BINARY", "data": "Zm9vYmFy" }, "value": { "type": "AVRO", "subject":"greetings.request-value", "schema_version":17, "data": { "greetings": "hello" } }'
解决方法
错误原因是请求体中同时指定了type: "AVRO"和schema_version字段,二者存在冲突。根据Confluent Kafka REST V3 API规范,当通过schema_version或schema_id引用已注册的AVRO Schema时,不需要额外指定type字段——系统会自动通过Schema Registry匹配对应的序列化器。
修正后的请求代码如下:
curl --location 'https://{host}/kafka/v3/clusters/{cluster}/topics/{topic-name}/records' \ --header 'Confluent-Identity-Pool-Id: {pool-id}' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer jwt_token' \ --data '{ "partition_id": 0, "key": { "type": "BINARY", "data": "Zm9vYmFy" }, "value": { "subject":"greetings.request-value", "schema_version":17, "data": { "greetings": "hello" } }'
内容的提问来源于stack exchange,提问作者sai jyothsna pentyala
相关产品推荐
相关产品推荐

