Confluence Schema Registry 为您的元数据提供了一个服务层。它提供了一个 RESTful 接口,用于存储和检索 Avro®、JSON 架构和 Protobuf 架构。它根据指定的主题名称策略存储所有模式的版本化历史记录,提供多种兼容性设置,并允许根据配置的兼容性设置和对这些模式类型的扩展支持来演变模式。它提供插入 Apache Kafka® 客户端的序列化程序,处理以任何支持的格式发送的 Kafka 消息的模式存储和检索。
本自述文件包括以下部分:
以下是 Confluence 文档中架构注册表页面的一些链接。
以下假设您有 Kafka 和使用默认设置运行的架构注册表实例。这些示例以及更多示例也可以在 docs.confluence.io 上的 API 使用示例中找到。
# Register a new version of a schema under the subject "Kafka-key"
$ curl -X POST -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"schema": "{"type": "string"}"} '
http://localhost:8081/subjects/Kafka-key/versions
{ " id " :1}
# Register a new version of a schema under the subject "Kafka-value"
$ curl -X POST -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"schema": "{"type": "string"}"} '
http://localhost:8081/subjects/Kafka-value/versions
{ " id " :1}
# List all subjects
$ curl -X GET http://localhost:8081/subjects
[ " Kafka-value " , " Kafka-key " ]
# List all schema versions registered under the subject "Kafka-value"
$ curl -X GET http://localhost:8081/subjects/Kafka-value/versions
[1]
# Fetch a schema by globally unique id 1
$ curl -X GET http://localhost:8081/schemas/ids/1
{ " schema " : " " string " " }
# Fetch version 1 of the schema registered under subject "Kafka-value"
$ curl -X GET http://localhost:8081/subjects/Kafka-value/versions/1
{ " subject " : " Kafka-value " , " version " :1, " id " :1, " schema " : " " string " " }
# Fetch the most recently registered schema under subject "Kafka-value"
$ curl -X GET http://localhost:8081/subjects/Kafka-value/versions/latest
{ " subject " : " Kafka-value " , " version " :1, " id " :1, " schema " : " " string " " }
# Delete version 3 of the schema registered under subject "Kafka-value"
$ curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/3
3
# Delete all versions of the schema registered under subject "Kafka-value"
$ curl -X DELETE http://localhost:8081/subjects/Kafka-value
[1, 2, 3, 4, 5]
# Check whether a schema has been registered under subject "Kafka-key"
$ curl -X POST -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"schema": "{"type": "string"}"} '
http://localhost:8081/subjects/Kafka-key
{ " subject " : " Kafka-key " , " version " :1, " id " :1, " schema " : " " string " " }
# Test compatibility of a schema with the latest schema under subject "Kafka-value"
$ curl -X POST -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"schema": "{"type": "string"}"} '
http://localhost:8081/compatibility/subjects/Kafka-value/versions/latest
{ " is_compatible " :true}
# Get top level config
$ curl -X GET http://localhost:8081/config
{ " compatibilityLevel " : " BACKWARD " }
# Update compatibility requirements globally
$ curl -X PUT -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"compatibility": "NONE"} '
http://localhost:8081/config
{ " compatibility " : " NONE " }
# Update compatibility requirements under the subject "Kafka-value"
$ curl -X PUT -H " Content-Type: application/vnd.schemaregistry.v1+json "
--data ' {"compatibility": "BACKWARD"} '
http://localhost:8081/config/Kafka-value
{ " compatibility " : " BACKWARD " }
您可以下载架构注册表的预构建版本,作为 Confluence 平台的一部分。要从源安装,请按照开发部分中的说明进行操作。
模式注册表的 REST 接口包括一个内置的 Jetty 服务器。包装器脚本bin/schema-registry-start
和bin/schema-registry-stop
是启动和停止服务的推荐方法。
要构建开发版本,您可能需要common 和rest-utils 的开发版本。安装这些之后,您可以使用 Maven 构建架构注册表。
该项目使用 Google Java 代码风格来保持代码整洁和一致。
构建:
mvn compile
要运行单元测试和集成测试:
mvn test
要针对本地 Kafka 集群运行架构注册表实例(使用 Kafka 附带的默认配置):
mvn exec:java -pl :kafka-schema-registry -Dexec.args= " config/schema-registry.properties "
要创建打包版本,可以选择跳过测试:
mvn package [-DskipTests]
它生产:
package-schema-registry/target/kafka-schema-registry-package-$VERSION-package
package-kafka-serde-tools/target/kafka-serde-tools-package-$VERSION-package
中 avro/json/protobuf 的 Serde 工具每个生成的文件都包含与打包的二进制版本类似的目录布局。
您还可以使用standalone
配置文件生成架构注册表的独立 fat JAR:
mvn package -P standalone [-DskipTests]
这会生成package-schema-registry/target/kafka-schema-registry-package-$VERSION-standalone.jar
,其中也包含所有依赖项。
OpenAPI(以前称为 Swagger)规范是在compile
阶段使用swagger-maven-plugin
自动构建的。
感谢您帮助我们使架构注册表变得更好!
该项目已获得 Confluence 社区许可证的许可,但client-*
和avro-*
库除外,它们属于 Apache 2.0 许可证。有关详细许可协议,请参阅每个子文件夹中的 LICENSE 文件。