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 檔案。