You need to enable JavaScript to run this app. 如何通过Kafka-Rest注册Protobuf Schema并解决415媒体类型报错
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Kafka-Rest注册Protobuf Schema并解决415媒体类型报错

错误根因

你遇到的415 Unsupported Media Type错误是两点配置问题导致的:

  1. 仅适配Avro格式的请求参数:旧版REST Proxy提交Avro schema时仅需传value_schema字段,但Protobuf格式必须额外显式声明schema类型
  2. 部分版本REST Proxy对Protobuf请求的媒体类型校验规则更严格,需要同步确认服务端的扩展配置已开启Protobuf支持

正确请求配置

修正后的curl请求如下:

curl -X POST -H "Content-Type: application/vnd.kafka.protobuf.v2+json" \
   -H "Accept: application/vnd.kafka.v2+json" \
   --data '{"value_schema": "syntax=\"proto3\"; message User { string name = 1; }", "value_schema_type": "PROTOBUF", "records": [{"value": {"name": "testUser"}}]}' \
   "http://localhost:8082/topics/protobuftest"

异常排查

如果修改后依然报错,可按以下顺序检查:

  • 确认Kafka REST Proxy配置文件中已开启Schema Registry扩展:kafka.rest.resource.extension.class=io.confluent.kafka.rest.extensions.SchemaRegistryRestExtension
  • 确认schema.registry.url配置正确,且Schema Registry服务正常运行
  • 如果你使用的是7.0以上版本的Confluent Platform,也可尝试将Content-Type替换为application/json,高版本REST Proxy支持通用JSON格式解析带schema的提交请求
  • 若对应schema已经在Registry中注册过,可直接传递value_schema_id参数代替完整schema内容,避免重复注册和格式校验问题

内容的提问来源于stack exchange,提问作者Eugene Goldberg

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.13 02:18:03