搶先一步
VMware 提供培訓和認證,以加速您的進程。
瞭解更多本部落格提供 Spring Cloud Stream 4.0.x 版本中 Schema Registry 支援的更新。
許多企業使用 Schema Registry 來處理 schema 演進的使用案例,例如 Confluent Schema Registry。從 Spring Cloud Stream 的 1.1.x
版本到 3.0.0
版本,我們提供了 schema registry 伺服器和基於 AVRO 的 schema registry 用戶端轉換器,可以用於協調 schema registry 伺服器的 schema。Spring Cloud Stream 3.0.0 版本將 Schema Registry 元件移動到頂層的 spring-cloud 專案,並且 Spring Cloud Stream 將它們包含在其 BOM 中,供終端使用者應用程式使用。然而,這種方式擴展性不佳,因此在 3.2 版本中,我們決定停止將它們作為 Spring Cloud Stream BOM 的一部分。
Schema Registry 的使用案例在串流應用程式中非常重要,並且社群一直渴望核心 Spring Cloud Stream 提供解決方案。我們很高興地通知您,Schema Registry 元件已回歸到 Spring Cloud Stream 的 4.0.0 版本。對於這些 schema registry 元件來說,這是一個完整的循環。下面,我們將重新介紹這些元件,並簡要概述它們的功能。
Spring Cloud Stream 4.0.x
版本提供了一個獨立的 Schema Registry 伺服器,專門為 Spring Cloud Stream 解決的使用案例而客製化。這些使用案例包括跨多個 schema 版本的 schema 演進。這些使用案例的主要要點是生產者應用程式使用先前的 schema 版本發布,但消費者可以處理所有向後相容的 schema 版本。這些工作流程包括 schema 驗證,以及使用經過驗證的 schema 作為合約,並作為訊息轉換器進行資料序列化的基礎。我們不建議在 Spring Cloud Stream 之外使用此 Schema Registry 伺服器。預設情況下,此 Schema Registry 伺服器使用記憶體中的 H2 資料庫作為後端儲存。但是,您可以使用 Postgres 或 MySQL 作為後端資料庫。Spring Cloud Stream 提供此 Schema Registry 伺服器作為一個完整的 Spring Boot 應用程式。因此,您可以直接從 maven central 下載它(當 Spring Cloud Stream 4.0.0
正式發布時)。如果您想在快照或里程碑版本上試用它,您可以從相關的 Artifactory 儲存庫下載它。以下是 4.0.0-SNAPSHOT
版本的 maven 座標。如果您不想使用快照進行測試,也可以使用 4.0.0-M5
或 4.0.0-RC1
。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-schema-registry-server</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
假設您想使用獨立的 Schema Registry 伺服器以外的其他東西,而是使用自訂伺服器。在這種情況下,您可以將伺服器模組作為依賴項包含在您的應用程式中,並透過啟用 @EnableSchemaRegistryServer
來建立自訂 Spring Boot 應用程式。如果您有不受支援的後端儲存,則應使用此策略。
Spring Cloud Stream 4.0.0
還提供了一個 Schema Registry 用戶端模組,該模組提供基於 AVRO 的訊息轉換器。這些轉換器知道 Schema Registry,並與 Schema Registry 伺服器通信以在轉換有效負載以進行序列化時協調 schema。應用程式需要使用註釋 @EnableSchemaRegistryClient
,以透過 SchemaRegistryClient
bean 讓它們知道 schema registry 伺服器。Spring Boot 會自動配置知道 schema registry 的基於 AVRO 的訊息轉換器。
以下是 4.0.0-SNAPSHOT
版本的 schema registry 用戶端模組的 maven 座標。您也可以使用 4.0.0-M5
或 4.0.0-RC1
。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-schema-registry-client</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
Confluent Schema Registry 是一個流行的商業解決方案,用於基於 Kafka 的應用程式的 schema 演進。上述 Spring Cloud Stream AVRO 訊息轉換器可以與 Confluent Schema Registry 一起使用。為了使其能夠工作,應用程式需要覆寫 SchemaRegistryClient
bean 並為 ConfluentSchemaRegistryClient
提供實作。
我們提供了一組範例應用程式,展示了本部落格中描述的所有概念 這裡。請參閱 README 了解更多詳細資訊。
這裡 是 Schema Registry 參考文件。
Spring Cloud Stream 4.0.0
重新引入了 Spring Cloud Stream 早期版本的 Schema Registry 元件。本部落格檢驗了重新引入支援的動機和概述。Spring Cloud Stream 中提供的支援可能僅涵蓋一些 schema 演進的使用案例。然而,提供的 schema registry 元件可以支援許多屬於 Spring Cloud Stream 應用程式範圍內的 schema 演進使用案例,並提供與傳輸方式無關的附加價值。