This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.
Modern event streaming scenarios often use structured data in the event or message payload. Using schema-driven formats such as Avro to serialize and deserialize data is becoming increasingly important when exchanging such structured data between producer and consumer applications. Schema registries such as Azure Schema Registry for Event Hubs play a vital role in managing these schemas by providing a central repository and allowing the producer applications to make schema available for its consumers without directly managing or sharing schemas.
Today, we are announcing the general availability of the Azure Schema Registry in Azure Event Hubs.
Why Azure Schema Registry?
Azure Schema Registry is a feature of Event Hubs, which provides a central repository for schema documents for event-driven and messaging-centric applications. Azure Schema Registry allows the producer and consumer applications to exchange data without having to manage and share the schema.
Here are some of the key reasons for using Azure Schema Registry in your event streaming applications.
Validation of events stream data
When you use Azure Schema Registry, your producer and consumer applications can be implemented such that they validate event data that they publish or consume. For structured data that you produce or consume through Event Hubs, you can use schema-driven formats such as Avro and manage those schemas using Azure Schema Registry, irrespective of the event streaming protocol (AMQP, Kafka etc.) that you use to stream data. This provides better interoperability, prevents publishing or consuming invalid data, and prevents incompatibilities between producers and consumers.
Make schema available to consumers
The structured event data published to the Event Hubs needs to be consumed by the downstream consumer applications. By using Azure Schema Registry, you can make the schema available to existing and new consumers, so that they can build the consumer logic and validate event data that they are receiving.
Reducing per-event data overage
In schema-driven serialization/de-serialization of event payloads, if you don’t use a schema registry to share schemas, you need to append schema information to each event payload, which drastically increases the per-event data overage.
Azure Schema Registry reduces the event data overage by enabling the producers to only send a reference (schema ID) to the schema information with each event payload, which can be used by the consumer to retrieve the corresponding schema via Azure Schema Registry to deserialize event payload.
Azure Schema Registry for Event Hubs provides you a unified schema management experience. It provides a simple governance framework for reusable schemas and defines the relationship between schemas through a grouping construct called schema groups. Based on the business use cases, you can organize schemas into schema groups, define compatibility modes per each group, and create multiple versions of the schemas adhering to the compatibility mode specified in the schema group.
Schemas need to evolve with the business requirement of producers and consumers. Azure Schema Registry supports schema evolution by introducing compatibility modes feature at the schema group level. Compatibility modes allow producers and consumers to evolve independently. Based on the compatibility mode defined in the schema group, only certain operations are allowed when modifying and creating new schema versions. Azure Schema Registry currently supports Backward, Forward, and No compatibility modes.
Open Standards and Interoperability
Even though schema registries are increasingly popular, there has so far been no open and vendor-neutral standard for a lightweight interface optimized for this use-case. Microsoft has submitted the interface of the Azure Schema Registry to the Cloud Native Foundation's "Cloud Events" project in June 2020.
Event streaming with schema validation
The information flow of using Azure Schema Registry for event streaming in Azure Event Hubs is the same across different protocols that you use to publish or consume events. The following diagram shows the information flow of a Kafka event producer and consumer that uses Azure Schema Registry.
The information flow starts from the producer where the Kafka producer serializes the event data using the schema document. The producer then prepends the schema ID to the serialized event payload. Once the consumer receives the event, it can resolve the corresponding schema from the schema registry and deserialize the event payload.
Schema validation and event streaming for Kafka APIs
Azure Schema Registry for Event Hubs provides seamless integration with your Kafka Applications. If use Apache Kafka® with the Java client today and you are already using a schema-registry backed serializer, you will find that it's trivial to switch to the Azure Schema Registry's Avro serializer just by modifying the client configuration.
You can update your Kafka producer applications configuration to use Azure Schema Registry as shown in the following code snippet.
Then you can publish event data to Azure Event Hubs using its Kafka API with a strongly typed producer as shown below.
Similarly, you need to update a few configurations at your Kafka consumer application to consume and deserialize event data using Azure Schema Registry.
For a complete sample on using Azure Schema Registry with Event Hubs Kafka API, please check this quickstart guide.
Schema validation and event streaming with Azure SDKs
You can use Azure SDKs to directly interact with Azure Schema Registry for Event Hubs. Therefore, you can build schema validations for applications that use the native protocol (AMQP) of Event Hubs, using Azure Schema Registry SDKs.
The Avro serializers for all Azure SDK languages implement the same base class or pattern that is used for serialization throughout the SDK and can therefore be used with all Azure SDK clients that already have or will offer object serialization extensibility.
Serializing data with Azure Schema Registry SDK - .NET
With the Azure Schema Registry SDK, the serializer interface turns structured data into a byte stream (or byte array) and back. It can therefore be used anywhere and with any framework or service. Here is a snippet that uses the serializer with automatic schema registration in C#:
If you want to publish serialized event payload to Event Hubs via native (AMQP) protocol, you can do so as you would send any event data to Event Hub.
De-serializing data with Azure Schema Registry SDK - .NET
You can use Azure Schema Registry SDKs to deserialize the event data as shown in the following C# code snippet.
For a complete sample on using Azure Schema Registry SDKs and event streaming using Event Hubs native protocol, please follow this quick start guide.
Get Started Today
To try out and learn more about Azure Schema Registry GA in Event Hubs check out the below links.
- You can start using Azure Schema Registry in Event Hubs via the Azure portal.
- Want to learn more? Check out Azure Schema Registry in Event Hubs - Overview.