Last active
October 17, 2020 13:12
Star
You must be signed in to star a gist
Introduction to Schema Registry for Azure Messaging Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
az group deployment create \ | |
-g [RESOURCE_GROUP_NAME] \ | |
-n [DEPLOYMENT_NAME] \ | |
--template-file StorageAccount.json \ | |
--parameters @StorageAccount.parameters.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Upload schema of `SampleClass` | |
var version = "v1"; | |
var filename = "schema.json"; | |
var filepath = $"{version}/{filename}"; | |
var produced = await producer.ProduceAsync<SampleClass>(filepath) | |
.ConfigureAwait(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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