You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 22:52:34