|
| 1 | +--- |
| 2 | +title: Configure WebAssembly Graph Definitions For Data Flow Graphs (Preview) |
| 3 | +description: Learn how to create and configure WebAssembly graph definitions that define data processing workflows for Azure IoT Operations data flow graphs. |
| 4 | +author: PatAltimore |
| 5 | +ms.author: patricka |
| 6 | +ms.service: azure-iot-operations |
| 7 | +ms.subservice: azure-data-flows |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 08/01/2025 |
| 10 | +ai-usage: ai-assisted |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +# Configure WebAssembly (WASM) graph definitions for data flow graphs (preview) |
| 15 | + |
| 16 | +> [!IMPORTANT] |
| 17 | +> WebAssembly (WASM) graph definitions for data flow graphs are in **preview**. This feature has limitations and is not for production workloads. |
| 18 | +> |
| 19 | +> See the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/) for legal terms that apply to Azure features that are in beta, preview, or not yet released into general availability. |
| 20 | +
|
| 21 | +Graph definitions are central to WASM development because they define how your modules connect to processing workflows. Understanding the relationship between graph definitions and data flow graphs helps you develop effectively. |
| 22 | + |
| 23 | +This article focuses on creating and configuring the YAML graph definitions. For information about deploying and testing WASM data flow graphs, see [Use WebAssembly with data flow graphs](howto-dataflow-graph-wasm.md). |
| 24 | + |
| 25 | +## Graph definition structure |
| 26 | + |
| 27 | +Graph definitions follow a formal [JSON schema](https://github.com/Azure-Samples/explore-iot-operations/blob/wasm/samples/wasm/ConfigGraph.json) that validates structure and ensures compatibility. The configuration includes: |
| 28 | + |
| 29 | +- Module requirements for API and host library version compatibility |
| 30 | +- Module configurations for runtime parameters and operator customization |
| 31 | +- Operations that define processing nodes in your workflow |
| 32 | +- Connections that specify data flow routing between operations |
| 33 | +- Schemas for optional data validation |
| 34 | + |
| 35 | +## Basic graph structure |
| 36 | + |
| 37 | +```yaml |
| 38 | +moduleRequirements: |
| 39 | + apiVersion: "0.2.0" |
| 40 | + hostlibVersion: "0.2.0" |
| 41 | + |
| 42 | +operations: |
| 43 | + - operationType: "source" |
| 44 | + name: "data-source" |
| 45 | + - operationType: "map" |
| 46 | + name: "my-operator/map" |
| 47 | + module: "my-operator:1.0.0" |
| 48 | + - operationType: "sink" |
| 49 | + name: "data-sink" |
| 50 | + |
| 51 | +connections: |
| 52 | + - from: { name: "data-source" } |
| 53 | + to: { name: "my-operator/map" } |
| 54 | + - from: { name: "my-operator/map" } |
| 55 | + to: { name: "data-sink" } |
| 56 | +``` |
| 57 | +
|
| 58 | +## Version compatibility |
| 59 | +
|
| 60 | +The `moduleRequirements` section ensures compatibility using semantic versioning: |
| 61 | + |
| 62 | +```yaml |
| 63 | +moduleRequirements: |
| 64 | + apiVersion: "0.2.0" # WASI API version for interface compatibility |
| 65 | + hostlibVersion: "0.2.0" # Host library version providing runtime support |
| 66 | + features: # Optional features required by modules |
| 67 | + - name: "wasi-nn" |
| 68 | +``` |
| 69 | + |
| 70 | +## Example 1: Simple graph definition |
| 71 | + |
| 72 | +The [simple graph definition](https://github.com/Azure-Samples/explore-iot-operations/blob/wasm/samples/wasm/graph-simple.yaml) demonstrates a basic three-stage pipeline that converts temperature data from Fahrenheit to Celsius: |
| 73 | + |
| 74 | +:::code language="yaml" source="~/azure-iot-operations-samples/samples/wasm/graph-simple.yaml"::: |
| 75 | + |
| 76 | +For step-by-step deployment instructions and testing guidance for this example, see [Example 1: Basic deployment with one WASM module](howto-dataflow-graph-wasm.md#example-1-basic-deployment-with-one-wasm-module). |
| 77 | + |
| 78 | +### How the simple graph works |
| 79 | + |
| 80 | +This graph creates a straightforward data processing pipeline: |
| 81 | + |
| 82 | +1. **Source operation**: Receives temperature data from the data flow's source endpoint |
| 83 | +2. **Map operation**: Processes data with the temperature WASM module (`temperature:1.0.0`) |
| 84 | +3. **Sink operation**: Sends converted data to the data flow's destination endpoint |
| 85 | + |
| 86 | +The [temperature module](https://github.com/Azure-Samples/explore-iot-operations/blob/wasm/samples/wasm/operators/temperature/src/lib.rs) converts Fahrenheit to Celsius using the standard formula `(F - 32) × 5/9 = C`. |
| 87 | + |
| 88 | +**Input format:** |
| 89 | +```json |
| 90 | +{"temperature": {"value": 100.0, "unit": "F"}} |
| 91 | +``` |
| 92 | + |
| 93 | +**Output format:** |
| 94 | +```json |
| 95 | +{"temperature": {"value": 37.8, "unit": "C"}} |
| 96 | +``` |
| 97 | + |
| 98 | +## Example 2: Complex graph definition |
| 99 | + |
| 100 | +The [complex graph definition](https://github.com/Azure-Samples/explore-iot-operations/blob/wasm/samples/wasm/graph-complex.yaml) demonstrates a sophisticated multi-sensor processing workflow that handles temperature, humidity, and image data with advanced analytics: |
| 101 | + |
| 102 | +:::code language="yaml" source="~/azure-iot-operations-samples/samples/wasm/graph-complex.yaml"::: |
| 103 | + |
| 104 | +For step-by-step deployment instructions and testing guidance for this example, see [Example 2: Deploy a complex graph](howto-dataflow-graph-wasm.md#example-2-deploy-a-complex-graph). |
| 105 | + |
| 106 | +### How the complex graph works |
| 107 | + |
| 108 | +The complex graph processes three data streams and combines them into enriched sensor analytics: |
| 109 | + |
| 110 | +<!-- |
| 111 | +```mermaid |
| 112 | +graph TD |
| 113 | + source["source"] |
| 114 | + delay["module-window/delay"] |
| 115 | + branch_snapshot["module-snapshot/branch"] |
| 116 | + branch_temp["module-temperature/branch"] |
| 117 | + map_temp["module-temperature/map (F -> C)"] |
| 118 | + filter_temp["module-temperature/filter (valid)"] |
| 119 | + accumulate_temp["module-temperature/accumulate (max, min, avg, last)"] |
| 120 | + accumulate_humidity["module-humidity/accumulate (max, min, avg, last)"] |
| 121 | + map_format["module-format/map (image, snapshot)"] |
| 122 | + map_snapshot["module-snapshot/map (object detection)"] |
| 123 | + accumulate_snapshot["module-snapshot/accumulate (collection)"] |
| 124 | + concatenate["concatenate"] |
| 125 | + accumulate_collection["module-collection/accumulate"] |
| 126 | + map_enrichment["module-enrichment/map (overtemp, topic)"] |
| 127 | + sink["sink"] |
| 128 | + source - -> delay |
| 129 | + delay - -> branch_snapshot |
| 130 | + branch_snapshot - ->|sensor data| branch_temp |
| 131 | + branch_snapshot - ->|snapshot| map_format |
| 132 | + map_format - -> map_snapshot |
| 133 | + map_snapshot - -> accumulate_snapshot |
| 134 | + accumulate_snapshot - -> concatenate |
| 135 | + branch_temp - ->|temp| map_temp |
| 136 | + branch_temp - ->|humidity| accumulate_humidity |
| 137 | + map_temp - -> filter_temp |
| 138 | + filter_temp - -> accumulate_temp |
| 139 | + accumulate_temp - -> concatenate |
| 140 | + accumulate_humidity - -> concatenate |
| 141 | + concatenate - -> accumulate_collection |
| 142 | + accumulate_collection - -> map_enrichment |
| 143 | + map_enrichment - -> sink |
| 144 | +``` |
| 145 | +--> |
| 146 | + |
| 147 | +:::image type="content" source="media/howto-configure-wasm-graph-definitions/wasm-dataflow-graph-complex.svg" alt-text="Diagram showing a complex data flow graph example with multiple modules." border="false"::: |
| 148 | + |
| 149 | +As shown in the diagram, data flows from a single source through multiple processing stages: |
| 150 | + |
| 151 | +1. **Window module**: Delays incoming data for time-based processing |
| 152 | +2. **Branch operation**: Routes data based on content type (sensor data vs. snapshots) |
| 153 | +3. **Temperature processing path**: |
| 154 | + - Converts Fahrenheit to Celsius |
| 155 | + - Filters invalid readings |
| 156 | + - Calculates statistical summaries over time windows |
| 157 | +4. **Humidity processing path**: |
| 158 | + - Accumulates humidity measurements with statistical analysis |
| 159 | +5. **Image processing path**: |
| 160 | + - Formats image data for processing |
| 161 | + - Performs object detection on camera snapshots |
| 162 | +6. **Final aggregation**: |
| 163 | + - Concatenates all processed data streams |
| 164 | + - Aggregates multi-sensor results |
| 165 | + - Adds metadata and overtemperature alerts |
| 166 | + |
| 167 | +The graph uses specialized modules from the [Rust examples](https://github.com/Azure-Samples/explore-iot-operations/tree/wasm/samples/wasm/rust/examples): |
| 168 | + |
| 169 | +- Window module for time-based processing delays |
| 170 | +- Temperature modules for conversion, filtering, and statistical analysis |
| 171 | +- Humidity module for environmental data processing |
| 172 | +- Snapshot modules for image data routing and object detection |
| 173 | +- Format module for image preparation for processing |
| 174 | +- Collection module for multi-sensor data aggregation |
| 175 | +- Enrichment module for metadata addition and alert generation |
| 176 | + |
| 177 | +Branch operations enable parallel processing of different sensor inputs, allowing the graph to handle multiple data types efficiently within a single workflow. |
| 178 | + |
| 179 | +## How graph definitions become data flows |
| 180 | + |
| 181 | +Here's how graph definitions and Azure IoT Operations data flow graphs relate: |
| 182 | + |
| 183 | +Your YAML file defines the internal processing logic with source/sink operations as abstract endpoints. This becomes the graph definition artifact. Referenced modules implement the actual processing operators as WASM modules. Both graph definitions and WASM modules are uploaded to a container registry (such as Azure Container Registry) as OCI artifacts for registry storage. |
| 184 | + |
| 185 | +The Azure Resource Manager or Kubernetes resource "wraps" the graph definition and connects it to real endpoints as the data flow graph resource. During runtime deployment, the data flow engine pulls the artifacts from the registry and deploys them. For endpoint mapping, the abstract source/sink operations in your graph connect to actual MQTT topics, Azure Event Hubs, or other data sources. |
| 186 | + |
| 187 | +For example, this diagram illustrates the relationship between graph definitions, WASM modules, and data flow graphs: |
| 188 | + |
| 189 | +:::image type="content" source="media/howto-develop-wasm-modules/wasm-dataflow-overall-architecture.svg" alt-text="Diagram showing the relationship between graph definitions, WASM modules, and data flow graphs." border="false"::: |
| 190 | + |
| 191 | +<!-- |
| 192 | +```mermaid |
| 193 | +graph LR |
| 194 | + subgraph "Development" |
| 195 | + YML[Graph Definition YAML] |
| 196 | + WASM1[Temperature Module] |
| 197 | + WASM2[Filter Module] |
| 198 | + WASM3[Analytics Module] |
| 199 | + end |
| 200 | + |
| 201 | + subgraph "Registry (ACR)" |
| 202 | + OCI1[Graph:1.1.0] |
| 203 | + OCI2[Temperature:1.0.0] |
| 204 | + OCI3[Filter:2.1.0] |
| 205 | + OCI4[Analytics:1.5.0] |
| 206 | + end |
| 207 | + |
| 208 | + subgraph "Data Flow Graph" |
| 209 | + MQTT[Source Endpoint] |
| 210 | + subgraph GDE["Graph Execution"] |
| 211 | + S[source] - -> M1[temperature operator] |
| 212 | + M1 - -> M2[filter operator] |
| 213 | + M2 - -> M3[analytics operator] |
| 214 | + M3 - -> K[sink] |
| 215 | + end |
| 216 | + DEST[Destination Endpoint] |
| 217 | + |
| 218 | + MQTT - -> S |
| 219 | + K - -> DEST |
| 220 | + end |
| 221 | + |
| 222 | + YML -.-> OCI1 |
| 223 | + WASM1 -.-> OCI2 |
| 224 | + WASM2 -.-> OCI3 |
| 225 | + WASM3 -.-> OCI4 |
| 226 | + OCI1 -.-> GDE |
| 227 | + OCI2 -.-> M1 |
| 228 | + OCI3 -.-> M2 |
| 229 | + OCI4 -.-> M3 |
| 230 | +``` |
| 231 | +--> |
| 232 | + |
| 233 | +## Registry deployment |
| 234 | + |
| 235 | +Both graph definitions and WASM modules must be uploaded to a container registry as Open Container Initiative (OCI) artifacts before data flow graphs can reference them: |
| 236 | + |
| 237 | +- Graph definitions are packaged as OCI artifacts with media type `application/vnd.oci.image.config.v1+json` |
| 238 | +- WASM modules are packaged as OCI artifacts containing the compiled WebAssembly binary |
| 239 | +- Use semantic versioning (such as `my-graph:1.0.0`, `temperature-converter:2.1.0`) for proper dependency management |
| 240 | +- Registry support is compatible with Azure Container Registry, Docker Hub, and other OCI-compliant registries |
| 241 | + |
| 242 | +The separation enables reusable logic where the same graph definition deploys with different endpoints. It provides environment independence where development, staging, and production use different data sources. It also supports modular deployment where you update endpoint configurations without changing processing logic. |
| 243 | + |
| 244 | +For detailed instructions on uploading graph definitions and WASM modules to registries, see [Use WebAssembly with data flow graphs](howto-dataflow-graph-wasm.md). For complete deployment workflows including registry setup, authentication, and testing, see the examples in that guide. |
| 245 | + |
| 246 | +## Module configuration parameters |
| 247 | + |
| 248 | +Graph definitions can specify runtime parameters for WASM operators through module configurations: |
| 249 | + |
| 250 | +```yaml |
| 251 | +moduleConfigurations: |
| 252 | + - name: my-operator/map |
| 253 | + parameters: |
| 254 | + threshold: |
| 255 | + name: temperature_threshold |
| 256 | + description: "Temperature threshold for filtering" |
| 257 | + required: true |
| 258 | + unit: |
| 259 | + name: output_unit |
| 260 | + description: "Output temperature unit" |
| 261 | + required: false |
| 262 | +``` |
| 263 | + |
| 264 | +These parameters are passed to your WASM operator's `init` function at runtime, enabling dynamic configuration without rebuilding modules. For detailed examples of how to access and use these parameters in your Rust and Python code, see [Module configuration parameters](howto-develop-wasm-modules.md#module-configuration-parameters). |
| 265 | + |
| 266 | +For a complete implementation example, see the [branch module](https://github.com/Azure-Samples/explore-iot-operations/tree/main/samples/wasm/rust/examples/branch), which demonstrates parameter usage for conditional routing logic. |
| 267 | + |
| 268 | +## Next steps |
| 269 | + |
| 270 | +- [Develop WebAssembly modules for data flow graphs](howto-develop-wasm-modules.md) |
| 271 | +- [Use WebAssembly with data flow graphs](howto-dataflow-graph-wasm.md) |
| 272 | +- [Configure data flow endpoints](howto-configure-dataflow-endpoint.md) |
| 273 | + |
| 274 | +## Related content |
| 275 | + |
| 276 | +- [Configure registry endpoints](howto-configure-registry-endpoint.md) |
| 277 | +- [Configure MQTT data flow endpoints](howto-configure-mqtt-endpoint.md) |
0 commit comments