Händelser
17 mars 21 - 21 mars 10
Gå med i mötesserien för att skapa skalbara AI-lösningar baserat på verkliga användningsfall med andra utvecklare och experter.
Registrera dig nuDen här webbläsaren stöds inte längre.
Uppgradera till Microsoft Edge och dra nytta av de senaste funktionerna och säkerhetsuppdateringarna, samt teknisk support.
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.
Install the Azure Schema Registry client library for .NET with NuGet:
dotnet add package Azure.Data.SchemaRegistry
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
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.
To acquire authenticated credentials and start interacting with Azure resources, please see the getting started with Azure Identity guide.
The simplest 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.
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/Azure.Data.SchemaRegistry_1.4.0/sdk/identity/Azure.Identity/README.md
string fullyQualifiedNamespace = "{hostname}.servicebus.windows.net";
var client = new SchemaRegistryClient(fullyQualifiedNamespace: fullyQualifiedNamespace, credential: new DefaultAzureCredential());
A schema has 6 components:
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
.
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.
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
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 to be stored in the Azure Schema Registry.
string groupName = "<schema_group_name>";
string name = "employeeSample";
SchemaFormat format = SchemaFormat.Avro;
// Example schema's definition
string definition = @"
{
""type"" : ""record"",
""namespace"" : ""TestSchema"",
""name"" : ""Employee"",
""fields"" : [
{ ""name"" : ""Name"" , ""type"" : ""string"" },
{ ""name"" : ""Age"", ""type"" : ""int"" }
]
}";
Response<SchemaProperties> schemaProperties = client.RegisterSchema(groupName, name, definition, format);
Retrieve a previously registered schema ID from the Azure Schema Registry.
string groupName = "<schema_group_name>";
string name = "employeeSample";
SchemaFormat format = SchemaFormat.Avro;
// Example schema's content
string content = @"
{
""type"" : ""record"",
""namespace"" : ""TestSchema"",
""name"" : ""Employee"",
""fields"" : [
{ ""name"" : ""Name"" , ""type"" : ""string"" },
{ ""name"" : ""Age"", ""type"" : ""int"" }
]
}";
SchemaProperties schemaProperties = client.GetSchemaProperties(groupName, name, content, format);
string schemaId = schemaProperties.Id;
Retrieve a previously registered schema's content from the Azure Schema Registry with either a schema ID or the group name, schema name, and version.
var schemaId = "<schema_id>";
SchemaRegistrySchema schema = client.GetSchema(schemaId);
string definition = schema.Definition;
string groupName = "<schema_group_name>";
string name = "<schema_id>";
int version = 1;
SchemaRegistrySchema schema = client.GetSchema(groupName, name, version);
string definition = schema.Definition;
Information on troubleshooting steps will be provided as potential issues are discovered.
See Azure Schema Registry for additional information.
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.
Feedback om Azure SDK for .NET
Azure SDK for .NET är ett öppen källkod projekt. Välj en länk för att ge feedback:
Händelser
17 mars 21 - 21 mars 10
Gå med i mötesserien för att skapa skalbara AI-lösningar baserat på verkliga användningsfall med andra utvecklare och experter.
Registrera dig nu