ome*_*mer 6 protocol-buffers apache-kafka confluent-schema-registry
我正在运行 Kafka 架构注册表版本 5.5.2,并尝试注册一个包含对另一个架构的引用的架构。当引用的架构与引用架构位于同一包中时,我设法使用以下命令执行此操作curl:
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schemaType":"PROTOBUF","references": [{"name": "other.proto","subject": "other.proto","version": 1}],"schema":"syntax = \"proto3\"; package com.acme; import \"other.proto\";\n\nmessage MyRecord {\n string f1 = 1;\n OtherRecord f2 = 2;\n }\n"}' \
http://localhost:8081/subjects/test-schema/versions
Run Code Online (Sandbox Code Playgroud)
但是,当我更改引用模式的包名称时,如下所示:
syntax = "proto3";
package some.other.package;
message OtherRecord {
int32 other_id = 1;
}
Run Code Online (Sandbox Code Playgroud)
当我{"error_code":42201,"message":"Either the input schema or one its references is invalid"}尝试注册引用模式时,无论我在引用名称/主题下放置什么,都会出现这种情况。这是我的试验之一:
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schemaType":"PROTOBUF","references": [{"name": "other.proto","subject": "other.proto","version": 1}],"schema":"syntax = \"proto3\"; package com.acme; import \"some.package.other.proto\";\n\nmessage MyRecord {\n string f1 = 1;\n OtherRecord f2 = 2;\n }\n"}' \
http://localhost:8081/subjects/test-shcema/versions
Run Code Online (Sandbox Code Playgroud)
首先,您应该将您的另一个原型注册到架构注册表中。
使用以下语法创建一个 json (名为other-proto.json )文件:
{
"schemaType": "PROTOBUF",
"schema": "syntax = \"proto3\";\npackage com.acme;\n\nmessage OtherRecord {\n int32 other_id = 1;\n}\n"
}
Run Code Online (Sandbox Code Playgroud)
然后
curl -XPOST -H 'Content-Type:application/vnd.schemaregistry.v1+json' http://localhost:8081/subjects/other.proto/versions --data @other-proto.json
Run Code Online (Sandbox Code Playgroud)
现在您的模式注册表知道此模式作为主题other.proto的引用。如果您创建另一个 json 文件(名为testproto-value.json)作为
{
"schemaType": "PROTOBUF",
"references": [
{
"name": "other.proto",
"subject": "other.proto",
"version": 1
}
],
"schema": "syntax = \"proto3\";\npackage com.acme;\n\nimport \"other.proto\";\n\nmessage MyRecord {\n string f1 = 1;\n .com.acme.OtherRecord f2 = 2;\n}\n"
}
Run Code Online (Sandbox Code Playgroud)
并将其发布到架构注册表:
curl -XPOST -H 'Content-Type:application/vnd.schemaregistry.v1+json' http://localhost:8081/subjects/testproto-value/versions --data @testproto-value.json
Run Code Online (Sandbox Code Playgroud)
它会解决你的问题。因为testproto-value.json中的引用被注册表识别为other.proto主题。
| 归档时间: |
|
| 查看次数: |
2248 次 |
| 最近记录: |