我正试图使用以下命令将一个新模式注册到融合模式注册表中:
echo '{
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"age": {
"type": "integer"
},
"profession": {
"type": "string"
},
"Status": {
"type": "string"
},
"education": {
"type": "string"
}
}
}' |
jq '. | {schema: tojson}' |
curl -X POST "https://schema-registry.dev/subjects/cld-dev-pub-json-test-value/versions" -H "Content-Type:application/json" -d @-
{
"error_code": 42201,
"message": "Either the input schema or one its references is invalid"
}
它一直在失败,但当我使用kafka-json模式控制台生成器时,它似乎可以工作:
kafka-json-schema-console-producer --bootstrap-server kafka00.dev:9095 --producer.config kafka-client-dev.properties --topic cld-dev-pub-json-test --property schema.registry.url=https://schema-registry.dev --property basic.auth.credentials.source=USER_INFO --property schema.registry.basic.auth.user.info=username:password --property value.schema='{"type":"object","properties":{"id":{"type":"integer"} , "age":{"type":"integer"} , "profession":{"type":"string"},"Status" : {"type": "string" }, "education" : {"type": "string" }}}' < json_data.txt
当我检查模式注册表中的模式时,它似乎很好:
curl -s -u <USERNAME:PASSWORD> https://schema-registry.dev.kafka/subjects/cld-dev-pub-json-test-value/versions/latest | jq
{
"subject": "cld-dev-pub-json-test-value",
"version": 8,
"id": 2639,
"schemaType": "JSON",
"schema": "{"type":"object","properties":{"id":{"type":"integer"},"age":{"type":"integer"},"profession":{"type":"string"},"Status":{"type":"string"},"education":{"type":"string"}}}"
}
因此,看起来kafkajson模式控制台生产者api正在使用不同的解析器来进行模式验证。此外,我正试图效仿罗宾·莫法特的例子:
https://rmoff.net/2019/01/17/confluent-schema-registry-rest-api-cheatsheet/
即使我提出了这个问题,工程师们也无法为我提供解决方案。
有什么想法可以克服吗?
谢谢..:(
链接博客已有几年的历史,使用的是Avro,而不是JSON。
注册表API已更改为现在有两个可选字段schemaType
和references
。
默认schemaType将是AVRO,用于向后兼容性,而不是JSON。
试试这个
echo '{
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"age": {
"type": "integer"
},
"profession": {
"type": "string"
},
"Status": {
"type": "string"
},
"education": {
"type": "string"
}
}
}' |
jq '. | {schema: tojson, schemaType: "JSON"}'
例如
{
"schema": "{"type":"object","properties":{"id":{"type":"integer"},"age":{"type":"integer"},"profession":{"type":"string"},"Status":{"type":"string"},"education":{"type":"string"}}}",
"schemaType": "JSON"
}
基于@OneCricketer的答案。
echo '{
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"age": {
"type": "integer"
},
"profession": {
"type": "string"
},
"Status": {
"type": "string"
},
"education": {
"type": "string"
}
}
}' |
jq '. | {schema: tojson, schemaType: "JSON"}' |
curl -X POST "https://schema-registry.dev/subjects/cld-dev-pub-json-test-value/versions" -H "Content-Type:application/json" -d @-
这应该是注册模式的整个命令。