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

如何为同一Kafka Topic多事件类型配置Schema Registry及curl提交示例

提交包含oneOf引用的JSON Schema到Schema Registry的curl示例

要提交这种包含oneOf和外部引用的顶层Schema,需先确保被引用的Schema已注册到Schema Registry,再通过references参数声明依赖关系。以下是完整步骤:

1. 先注册被引用的基础Schema

分别提交Customer、Product、Order的Schema到对应的subject:

注册Customer Schema

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{
    "schema": "{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}},\"required\":[\"id\"]}"
  }' \
  http://localhost:8081/subjects/Customer-value/versions

注册Product Schema

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{
    "schema": "{\"type\":\"object\",\"properties\":{\"sku\":{\"type\":\"string\"},\"price\":{\"type\":\"number\"}},\"required\":[\"sku\"]}"
  }' \
  http://localhost:8081/subjects/Product-value/versions

注册Order Schema

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{
    "schema": "{\"type\":\"object\",\"properties\":{\"orderId\":{\"type\":\"string\"},\"customerId\":{\"type\":\"integer\"},\"products\":{\"type\":\"array\",\"items\":{\"$ref\":\"Product.schema.json\"}}},\"required\":[\"orderId\",\"customerId\"]}"
  }' \
  http://localhost:8081/subjects/Order-value/versions

2. 注册包含oneOf的顶层Schema

通过references数组声明所有依赖的Schema信息,将顶层Schema提交到目标subject:

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
  --data '{
    "schema": "{\"oneOf\":[{\"$ref\":\"Customer.schema.json\"},{\"$ref\":\"Product.schema.json\"},{\"$ref\":\"Order.schema.json\"}]}",
    "references": [
      {"name": "Customer-value", "version": "latest", "type": "JSON"},
      {"name": "Product-value", "version": "latest", "type": "JSON"},
      {"name": "Order-value", "version": "latest", "type": "JSON"}
    ]
  }' \
  http://localhost:8081/subjects/CompositeEvent-value/versions

参数说明

  • references数组中的每个对象需包含:
    • name:被引用Schema对应的subject名称(如上面的Customer-value)
    • version:可填具体版本号(如1)或latest表示使用该subject的最新版本
    • type:Schema类型,固定为JSON
  • 顶层Schema中$ref的文件名(如Customer.schema.json)会被Registry映射到references中对应的依赖Schema

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 12:10:38