Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, and management. This package provides an Avro serializer capable of serializing and deserializing payloads containing Schema Registry schema identifiers and Avro-encoded data.
Key links:
@azure/schema-registry-avro
packageInstall the Azure Text Analytics client library for JavaScript with npm
:
npm install @azure/schema-registry-avro
Provides API to serialize to and deserialize from Avro Binary Encoding plus a
header with schema ID. Uses
SchemaRegistryClient
from the @azure/schema-registry package
to get schema IDs from schema content or vice versa. The provided API has internal cache to avoid calling the schema registry service when possible.
The same format is used by schema registry serializers across Azure SDK languages.
Messages are encoded as follows:
4 bytes: Format Indicator
32 bytes: Schema ID
Remaining bytes: Avro payload (in general, format-specific payload)
const { DefaultAzureCredential } = require("@azure/identity");
const { SchemaRegistryClient } = require("@azure/schema-registry");
const { SchemaRegistryAvroSerializer } = require("@azure/schema-registry-avro");
const client = new SchemaRegistryClient("<endpoint>", new DefaultAzureCredential());
const serializer = new SchemaRegistryAvroSerializer(client, "<group>");
// Example Avro schema
const schema = JSON.stringify({
type: "record",
name: "Rating",
namespace: "my.example",
fields: [{ name: "score", type: "int" }]
});
// Example value that matches the Avro schema above
const value = { score: 42 };
// Serialize value to buffer
const buffer = await serializer.serialize(value, schema);
// Deserialize buffer to value
const deserializedValue = await serializer.deserialize(buffer);
Enabling logging may help uncover useful information about failures. In order to
see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment
variable to info
. Alternatively, logging can be enabled at runtime by calling
setLogLevel
in the @azure/logger
:
const { setLogLevel } = require("@azure/logger");
setLogLevel("info");
Please take a look at the samples directory for detailed examples on how to use this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
Generated using TypeDoc