Skip to content

Commit 78a327c

Browse files
committed
Module configuration refactor
1 parent a167a1b commit 78a327c

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

articles/iot-operations/connect-to-cloud/howto-configure-wasm-graph-definitions.md

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ For detailed instructions on uploading graph definitions and WASM modules to reg
245245

246246
## Module configuration parameters
247247

248-
Module configurations define runtime parameters that your WASM operators can access:
248+
Graph definitions can specify runtime parameters for WASM operators through module configurations:
249249

250250
```yaml
251251
moduleConfigurations:
@@ -261,45 +261,7 @@ moduleConfigurations:
261261
required: false
262262
```
263263

264-
## Consume parameters in code
265-
266-
Parameters are accessed through the `ModuleConfiguration` struct passed to your operator's `init` function:
267-
268-
### Rust example
269-
270-
```rust
271-
use tinykube_wasm_sdk::logger::{self, Level};
272-
use tinykube_wasm_sdk::ModuleConfiguration;
273-
274-
fn branch_init(configuration: ModuleConfiguration) -> bool {
275-
// Access required parameters
276-
if let Some(threshold_param) = configuration.parameters.get("temperature_threshold") {
277-
let threshold: f64 = threshold_param.parse().unwrap_or(25.0);
278-
logger::log(Level::Info, "branch", &format!("Using threshold: {}", threshold));
279-
}
280-
281-
// Access optional parameters with defaults
282-
let unit = configuration.parameters
283-
.get("output_unit")
284-
.map(|s| s.as_str())
285-
.unwrap_or("celsius");
286-
287-
true
288-
}
289-
```
290-
291-
### Python example
292-
293-
```python
294-
def temperature_converter_init(configuration):
295-
# Access configuration parameters
296-
threshold = configuration.get_parameter("temperature_threshold")
297-
unit = configuration.get_parameter("output_unit", default="celsius")
298-
299-
imports.logger.log(imports.logger.Level.INFO, "temperature-converter",
300-
f"Initialized with threshold={threshold}, unit={unit}")
301-
return True
302-
```
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).
303265

304266
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.
305267

articles/iot-operations/connect-to-cloud/howto-develop-wasm-modules.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,34 @@ fn my_branch(input: DataModel, timestamp: HybridLogicalClock) -> bool {
465465
}
466466
```
467467

468+
#### Module configuration parameters
469+
470+
Your WASM operators can receive runtime configuration parameters through the `ModuleConfiguration` struct passed to the `init` function. These parameters are defined in the graph definition and allow runtime customization without rebuilding modules.
471+
472+
```rust
473+
use tinykube_wasm_sdk::logger::{self, Level};
474+
use tinykube_wasm_sdk::ModuleConfiguration;
475+
476+
fn my_operator_init(configuration: ModuleConfiguration) -> bool {
477+
// Access required parameters
478+
if let Some(threshold_param) = configuration.parameters.get("temperature_threshold") {
479+
let threshold: f64 = threshold_param.parse().unwrap_or(25.0);
480+
logger::log(Level::Info, "my-operator", &format!("Using threshold: {}", threshold));
481+
}
482+
483+
// Access optional parameters with defaults
484+
let unit = configuration.parameters
485+
.get("output_unit")
486+
.map(|s| s.as_str())
487+
.unwrap_or("celsius");
488+
489+
logger::log(Level::Info, "my-operator", &format!("Output unit: {}", unit));
490+
true
491+
}
492+
```
493+
494+
For detailed information about defining configuration parameters in graph definitions, see [Module configuration parameters](howto-configure-wasm-graph-definitions.md#module-configuration-parameters).
495+
468496
#### Host APIs
469497

470498
Use the SDK to work with distributed services:
@@ -518,11 +546,22 @@ from map_impl.imports import types
518546

519547
# Implement the operator interface
520548
class Map(exports.Map):
549+
def init(self, configuration) -> bool:
550+
# Access configuration parameters
551+
threshold = configuration.get_parameter("temperature_threshold")
552+
unit = configuration.get_parameter("output_unit", default="celsius")
553+
554+
imports.logger.log(imports.logger.Level.INFO, "my-operator",
555+
f"Initialized with threshold={threshold}, unit={unit}")
556+
return True
557+
521558
def process(self, message: types.DataModel) -> types.DataModel:
522559
# Your processing logic here
523560
return message
524561
```
525562

563+
For detailed information about defining configuration parameters in graph definitions, see [Module configuration parameters](howto-configure-wasm-graph-definitions.md#module-configuration-parameters).
564+
526565
Logging through imports:
527566
```python
528567
# Access to structured logging

0 commit comments

Comments
 (0)