apache-kafka - Schema Registry - 注册自定义对象类型
问题描述
我想注册一个 Avro 模式,它在模式注册表上引用另一个 Avro 模式。
首先,我注册了以下基本 Avro 架构:
{
"type":"record",
"name":"Client",
"namespace":"com.test.client",
"doc": "Client Property specific information is specified in this object",
"fields" : [
{"name" : "name", "type" : [ "null", "string" ]},
{"name" : "address", "type" : [ "null", "string"]}
]
}
如果我尝试注册以下 Avro 架构,该架构引用“客户端”属性中的基本架构,则操作失败并出现错误 422
{
"type":"record",
"name":"AnotherObject",
"namespace":"com.test.client",
"fields":
[
{"name":"tenant", "type": [ "null", "long" ]},
{"name":"client", "type" : [ "null","com.test.client.Client"]}
]
}
似乎问题与指定自定义类型字段有关。
知道如何在模式注册表中注册相关模式时添加自定义类型吗?
解决方案
您可以使用模式引用让模式引用 Confluent Schema Registry 上的其他模式。
请注意,在 Confluent Platform 5.5中引入了对这种表示法的支持。
根据您的示例(根据https://docs.confluent.io/platform/current/schema-registry/develop/api.html#subjects提供的文档),您应该AnotherObject
在 POST 请求中使用以下有效负载注册新模式注册:
{
"schema":"{
\"type\":\"record\",
\"name\":\"AnotherObject\",
\"namespace\":\"com.test.client\",
\"fields\":[
{
\"name\":\"tenant\",
\"type\":[\"null\",\"long\"]
},
{
\"name\":\"client\",
\"type\":[\"null\",\"com.test.client.Client\"]
}
]
}",
"schemaType":"AVRO",
"references":[
{
"name":"com.test.client.Client",
"subject":"clientSubject",
"version":1
}
]
}
其中clientSubjectcom.test.client.Client
是您在注册架构时指定的主题名称。
正如您所看到的,使用这种方法基本上可以直接指定要使用的参考模式的版本。这非常有用,因为否则可能会出现不一致。
在以下链接中查看有关架构引用的更多信息的文档:https ://docs.confluent.io/platform/current/schema-registry/serdes-develop/serdes-avro.html#referenced-schemas-avro
推荐阅读
- dns - 为什么服务器找不到 pihole.service.consul: NXDOMAIN,我该如何解决这个问题?
- string - 从 Rapid7 OpenData 网站用 jq 提取一些字符串
- python - pyspark 3.0 KMeansModel 在设定的误差平方和内
- keras - 是否可以根据 Keras 中的输入实现层之间的切换?
- javascript - 使用 Javascript 检测图像加载
- reporting-services - RDLC 报告在空白和最后一页之间添加行
- cloudkit - 无法与 UICloudSharingController 共享;随着“上传”消息消失
- flask - Google Cloud Run 未加载 JS/Bootstrap 的一部分/Flask 引擎的一部分/静态文件的一部分
- node.js - UnhandledPromiseRejectionWarning:TypeError:无法读取 null 的属性“拆分”
- reactjs - 将自定义反应钩子作为道具传递是否有任何潜在问题