Schema registry, a feature provided by Azure Device Registry, is a synchronized repository in the cloud and at the edge. The schema registry stores the definitions of messages coming from edge assets, and then exposes an API to access those schemas at the edge.
The connector for OPC UA can create message schemas and add them to the schema registry or customers can upload schemas to the operations experience web UI or using ARM/Bicep templates.
Edge services use message schemas to filter and transform messages as they're routed across your industrial edge scenario.
Schemas are documents that describe the format of a message and its contents to enable processing and contextualization.
Message schema definitions
Schema registry expects the following required fields in a message schema:
Required field
Definition
$schema
Either http://json-schema.org/draft-07/schema# or Delta/1.0. In data flows, JSON schemas are used for source endpoints and Delta schemas are used for destination endpoints.
type
Object
properties
The message definition.
Sample schemas
The following sample schemas provide examples for defining message schemas in each format.
Message schemas are used in all three phases of a data flow: defining the source input, applying data transformations, and creating the destination output.
Input schema
Each data flow source can optionally specify a message schema. Currently, data flows doesn't perform runtime validation on source message schemas.
Asset sources have a predefined message schema that was created by the connector for OPC UA.
Schemas can be uploaded for message broker sources. Currently, Azure IoT Operations supports JSON for source schemas, also known as input schemas. In the operations experience, you can select an existing schema or upload one while defining a message broker source:
Transformation
The operations experience uses the input schema as a starting point for your data, making it easier to select transformations based on the known input message format.
Output schema
Output schemas are associated with data flow destinations.
In the operations experience portal, you can configure output schemas for the following destination endpoints that support Parquet output:
local storage
Fabric OneLake
Azure Storage (ADLS Gen2)
Azure Data Explorer
Note: The Delta schema format is used for both Parquet and Delta output.
If you use Bicep or Kubernetes, you can configure output schemas using JSON output for MQTT and Kafka destination endpoints. MQTT- and Kafka-based destinations don't support Delta format.
For these data flows, the operations experience applies any transformations to the input schema then creates a new schema in Delta format. When the data flow custom resource (CR) is created, it includes a schemaRef value that points to the generated schema stored in the schema registry.
Input schema can be uploaded in the operations experience portal as described in the Input schema section of this article. You can also upload a schema using the Azure CLI or a Bicep template.
Upload schema with the CLI
The az iot ops schema command group contains commands to create, view, and manage schemas in your schema registry.
You can upload a schema by referencing a JSON file or by including the schema as inline content.
The following example uses minimal inputs to create a schema called myschema from a file. When no version number is specified, the schema version is 1.
If you don't know your registry name, use the schema registry list command to query for it. For example:
Azure CLI
az iot ops schema registry list -g myresourcegroup --query"[].{Name:name}"-o tsv
Once the create command is completed, you should see a blob in your storage account container with the schema content. The name for the blob is in the format schema-namespace/schema/version.
You can see more options with the helper command az iot ops schema -h.
Upload schema with a Bicep template
Create a Bicep .bicep file, and add the schema content to it at the top as a variable. This example is a Delta schema that corresponds to the OPC UA data from quickstart.
Then, in the same file, just underneath the schema, define the schema resource along with pointers to the existing schema registry resource that you have from deploying Azure IoT Operations.
Bicep
// Replace placeholder values with your actual resource namesparamschemaRegistryNamestring = '<SCHEMA_REGISTRY_NAME>'// Pointers to existing resources from AIO deploymentresourceschemaRegistry'Microsoft.DeviceRegistry/schemaRegistries@2024-09-01-preview'existing = {
name: schemaRegistryName
}
// Name and version of the schemaparamopcuaSchemaNamestring = 'opcua-output-delta'paramopcuaSchemaVerstring = '1'// Define the schema resource to be created and instantiate a versionresourceopcSchema'Microsoft.DeviceRegistry/schemaRegistries/schemas@2024-09-01-preview' = {
parent: schemaRegistryname: opcuaSchemaNameproperties: {
displayName: 'OPC UA Delta Schema'description: 'This is a OPC UA delta Schema'format: 'Delta/1.0'schemaType: 'MessageSchema'
}
}
resourceopcuaSchemaVersion'Microsoft.DeviceRegistry/schemaRegistries/schemas/schemaVersions@2024-09-01-preview' = {
parent: opcSchemaname: opcuaSchemaVerproperties: {
description: 'Schema version'schemaContent: opcuaSchemaContent
}
}
After you've defined the schema content and resources, you can deploy the Bicep template to create the schema in the schema registry.
Azure CLI
az deployment group create --resource-group<RESOURCE_GROUP>--template-file<FILE>.bicep