Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Introduction to Schema Registry for Azure Messaging Service
// Declare the main schema registry
var mainConnectionString = "AZURE_MAIN_STORAGE_CONNECTION_STRING";
var mainBlobClient = CloudStorageAccount.Parse(mainConnectionString)
.CreateCloudBlobClient();
var mainBlobBaseUri = "AZURE_MAIN_BLOB_STORAGE_BASE_URI";
var mainSchemaContainer = "schemas";
var mainSink = new BlobStorageSchemaSink(mainBlobClient)
.WithBaseLocation(mainBlobBaseUri)
.WithContainer(mainSchemaContainer);
// Declare the backup schema registry
var backupConnectionString = "AZURE_BACKUP_STORAGE_CONNECTION_STRING";
var backupBlobClient = CloudStorageAccount.Parse(backupConnectionString)
.CreateCloudBlobClient();
var backupBlobBaseUri = "AZURE_BACKUP_BLOB_STORAGE_BASE_URI";
var backupSchemaContainer = "backups";
var backupSink = new BlobStorageSchemaSink(backupBlobClient)
.WithBaseLocation(backupBlobBaseUri)
.WithContainer(backupSchemaContainer);
// Declare JSON schema generator settings
var settings = new JsonSchemaGeneratorSettings();
// Declare schema builder
var builder = new SchemaBuilder()
.WithSettings(settings);
// Declare schema producer
var producer = new SchemaProducer()
.WithBuilder(builder)
.WithSink(mainSink)
.WithSink(backupSink);
az group deployment create \
-g [RESOURCE_GROUP_NAME] \
-n [DEPLOYMENT_NAME] \
--template-file StorageAccount.json \
--parameters @StorageAccount.parameters.json
// Upload schema of `SampleClass`
var version = "v1";
var filename = "schema.json";
var filepath = $"{version}/{filename}";
var produced = await producer.ProduceAsync<SampleClass>(filepath)
.ConfigureAwait(false);
var schema = "{ JSON_SCHEMA }";
// Upload schema directly
var version = "v1";
var filename = "schema.json";
var filepath = $"{version}/{filename}";
var produced = await producer.ProduceAsync(schema, filepath)
.ConfigureAwait(false);
...
resources:
# Declare Azure Storage Account
- comments: '### RESOURCE - STORAGE ACCOUNT ###'
apiVersion: "[variables('storageAccount').apiVersion]"
type: Microsoft.Storage/storageAccounts
name: "[variables('storageAccount').name]"
location: "[variables('storageAccount').location]"
kind: StorageV2
tags: "[variables('tags')]"
sku:
name: "[variables('storageAccount').sku.name]"
tier: "[variables('storageAccount').sku.tier]"
properties:
encryption:
keySource: Microsoft.Storage
services:
blob:
enabled: true
file:
enabled: true
# Declare Azure Blob Service
- comments: '### RESOURCE - STORAGE ACCOUNT - BLOB SERVICE ###'
apiVersion: "[variables('storageAccount').blob.apiVersion]"
type: Microsoft.Storage/storageAccounts/blobServices
name: "[variables('storageAccount').blob.name]"
dependsOn:
- "[variables('storageAccount').resourceId]"
properties:
cors:
corsRules: []
deleteRetentionPolicy:
enabled: false
# Declare Azure Blob Container
- comments: '### RESOURCE - STORAGE ACCOUNT - BLOB SERVICE - BLOB CONTAINER ###'
apiVersion: "[variables('storageAccount').blob.apiVersion]"
type: Microsoft.Storage/storageAccounts/blobServices/containers
copy:
name: containers
count: "[length(variables('storageAccount').blob.container.names)]"
name: "[concat(variables('storageAccount').blob.name, '/', variables('storageAccount').blob.container.names[copyIndex()])]"
dependsOn:
- "[variables('storageAccount').blob.resourceId]"
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.