• Public
  • Public/Protected
  • All


Package version

Azure Schema Registry Avro serializer client library for JavaScript

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:

Getting started


Install the @azure/schema-registry-avro package

Install the Azure Text Analytics client library for JavaScript with npm:

npm install @azure/schema-registry-avro

Key concepts


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 definition or vice versa. The provided API has internal cache to avoid calling the schema registry service when possible.

Message format

The same format is used by schema registry serializers across Azure SDK languages.

Messages are encoded as follows:

  • 4 bytes: Format Indicator

    • Currently always zero to indicate format below.
  • 32 bytes: Schema ID

    • UTF-8 hexadecimal representation of GUID.
    • 32 hex digits, no hyphens.
    • Same format and byte order as string from Schema Registry service.
  • Remaining bytes: Avro payload (in general, format-specific payload)

    • Avro Binary Encoding
    • NOT Avro Object Container File, which includes the schema and defeats the purpose of this serialzer to move the schema out of the message payload and into the schema registry.


Serialize and deserialize

const { DefaultAzureCredential } = require("@azure/identity");
const { SchemaRegistryClient } = require("@azure/schema-registry");
const { SchemaRegistryAvroSerializer } = require("@azure/schema-registry-avro");

const client = new SchemaRegistryClient("<fully qualified namespace>", new DefaultAzureCredential());
const serializer = new SchemaRegistryAvroSerializer(client, { groupName: "<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");


Next steps

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.

Related projects


Generated using TypeDoc