Azure.Data.SchemaRegistry 1.0.0-beta.3 Prefix Reserved

This is a prerelease version of Azure.Data.SchemaRegistry.
Install-Package Azure.Data.SchemaRegistry -Version 1.0.0-beta.3
dotnet add package Azure.Data.SchemaRegistry --version 1.0.0-beta.3
<PackageReference Include="Azure.Data.SchemaRegistry" Version="1.0.0-beta.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Data.SchemaRegistry --version 1.0.0-beta.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azure.Data.SchemaRegistry, 1.0.0-beta.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Data.SchemaRegistry as a Cake Addin
#addin nuget:?package=Azure.Data.SchemaRegistry&version=1.0.0-beta.3&prerelease

// Install Azure.Data.SchemaRegistry as a Cake Tool
#tool nuget:?package=Azure.Data.SchemaRegistry&version=1.0.0-beta.3&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Azure Schema Registry client library for .NET

Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, and management. The registry is leveraged by serializers to reduce payload size while describing payload structure with schema identifiers rather than full schemas.

Getting started

Install the package

Install the Azure Schema Registry client library for .NET with NuGet:

dotnet add package --prerelease Azure.Data.SchemaRegistry

Prerequisites

If you need to create an Event Hubs namespace, you can use the Azure Portal or Azure PowerShell.

You can use Azure PowerShell to create the Event Hubs namespace with the following command:

New-AzEventHubNamespace -ResourceGroupName myResourceGroup -NamespaceName namespace_name -Location eastus

Authenticate the client

In order to interact with the Azure Schema Registry service, you'll need to create an instance of the Schema Registry Client class. To create this client, you'll need Azure resource credentials and the Event Hubs namespace hostname.

Get credentials

To acquire authenicated credentials and start interacting with Azure resources, please see the quickstart guide here.

Get Event Hubs namespace hostname

The simpliest way is to use the Azure portal and navigate to your Event Hubs namespace. From the Overview tab, you'll see Host name. Copy the value from this field.

Create SchemaRegistryClient

Once you have the Azure resource credentials and the Event Hubs namespace hostname, you can create the SchemaRegistryClient. You'll also need the Azure.Identity package to create the credential.

// Create a new SchemaRegistry client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
// For more information on Azure.Identity usage, see: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md
var client = new SchemaRegistryClient(endpoint: endpoint, credential: new DefaultAzureCredential());

Key concepts

Schemas

A schema has 6 components:

  • Group Name: The name of the group of schemas in the Schema Registry instance.
  • Schema Name: The name of the schema.
  • Schema ID: The ID assigned by the Schema Registry instance for the schema.
  • Serialization Type: The format used for serialization of the schema. For example, Avro.
  • Schema Content: The string representation of the schema.
  • Schema Version: The version assigned to the schema in the Schema Registry instance.

These components play different roles. Some are used as input into the operations and some are outputs. Currently, SchemaProperties only exposes those properties that are potential outputs that are used in SchemaRegistry operations. Those exposed properties are Content and Id.

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

The following shows examples of what is available through the SchemaRegistryClient. There are both sync and async methods available for these client operations.

Register a schema

Register a schema to be stored in the Azure Schema Registry. When registering a schema, the SchemaProperties will be cached in the SchemaRegistryClient instance, so that any subsequent calls to GetSchemaId and GetSchema corresponding to the same schema can use the cached value rather than going to the service.

string schemaName = "employeeSample";
SerializationType schemaType = SerializationType.Avro;
// Example schema's content
string schemaContent = @"
{
   ""type"" : ""record"",
    ""namespace"" : ""TestSchema"",
    ""name"" : ""Employee"",
    ""fields"" : [
    { ""name"" : ""Name"" , ""type"" : ""string"" },
    { ""name"" : ""Age"", ""type"" : ""int"" }
    ]
}";

Response<SchemaProperties> schemaProperties = client.RegisterSchema(groupName, schemaName, schemaType, schemaContent);

Retrieve a schema ID

Retrieve a previously registered schema ID from the Azure Schema Registry. When looking up the schema Id, the SchemaProperties will be cached in the SchemaRegistryClient instance, so that subsequent requests for this schema do not need to go the service.

string schemaName = "employeeSample";
SerializationType schemaType = SerializationType.Avro;
// Example schema's content
string schemaContent = @"
{
   ""type"" : ""record"",
    ""namespace"" : ""TestSchema"",
    ""name"" : ""Employee"",
    ""fields"" : [
    { ""name"" : ""Name"" , ""type"" : ""string"" },
    { ""name"" : ""Age"", ""type"" : ""int"" }
    ]
}";

SchemaProperties schemaProperties = client.GetSchemaId(groupName, schemaName, schemaType, schemaContent);
string schemaId = schemaProperties.Id;

Retrieve a schema

Retrieve a previously registered schema's content from the Azure Schema Registry. When looking up the schema content by schema ID, the SchemaProperties will be cached in the SchemaRegistryClient instance so that subsequent requests for this schema ID do not need to go the service.

SchemaProperties schemaProperties = client.GetSchema(schemaId);
string schemaContent = schemaProperties.Content;

Troubleshooting

Information on troubleshooting steps will be provided as potential issues are discovered.

Next steps

See Azure Schema Registry for additional information.

Contributing

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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Azure.Data.SchemaRegistry:

Package Downloads
Microsoft.Azure.Data.SchemaRegistry.ApacheAvro

Microsoft Azure Schema Registry Apache Avro SDK

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta.3 126 8/17/2021
1.0.0-beta.2 25,446 9/23/2020
1.0.0-beta.1 9,126 9/9/2020