Edit

Route more than two message kinds

Give speed, temperature, and remaining messages separate processing paths. Check for speed first, then check the false path for temperature. Merge the results into one output stream.

Prerequisites

Complete the shared example prerequisites, including the default profile and factory-mqtt endpoint. Use YAML for debugging and Azure CLI or Bicep for production management.

Use the existing built-in registry endpoint named default. For the environment variables, set AIO_INSTANCE_NAME and RESOURCE_GROUP to your existing instance and resource group names. For Bicep, also set CUSTOM_LOCATION_NAME to your existing custom location name.

Configure the routing paths

Diagram of two built-in branches routing speed, temperature, and remaining messages, including unknown kinds, through separate paths. Concatenate forwards each processed message to one output stream without joining records.

Chain binary branches to make multiple paths, and use concatenate to merge them. Route missing and unknown message kinds through a fallback path.

Branches route messages after the source receives them. Concatenate forwards each message independently; messages from different paths can arrive in any order.

The expression input kind ?? "unknown" supplies a fallback when kind is missing; it doesn't add or rewrite the payload's kind field. For syntax, see Default values.

The remaining path contains humidity messages as well as missing, unknown, and unrecognized kinds. Keep unknown messages identifiable, and don't run humidity-specific calculations without checking the kind and required fields. If humidity needs a separate path, add a third branch on the remaining path with expression $1 == "humidity" and the same defaulted input.

For technical details, see Define a branch rule and Merge paths with concatenate.

Three map nodes label the path while preserving the input fields.

  1. In the operations experience, open your instance and select Data flow graph > Create data flow graph.

  2. Name the graph route-message-kinds and select the default profile.

  3. Add a source named source using endpoint factory-mqtt and topic factory/mixed-readings.

  4. Add two branch transforms using azureiotoperations/graph-dataflow-branch:1.1.0 from registry endpoint default. Configure one rule per transform:

    Transform name Input Expression
    speed-check kind ?? "unknown" $1 == "speed"
    temperature-check kind ?? "unknown" $1 == "temperature"
  5. Add three map transforms using azureiotoperations/graph-dataflow-map:1.0.0 from registry endpoint default. In each, add a rule with input *, output *, and no expression to preserve the fields. Add a second rule:

    Transform name Input Output Expression
    speed-path kind ?? "unknown" route "speed"
    temperature-path kind ?? "unknown" route "temperature"
    remaining-path kind ?? "unknown" route "remaining"
  6. Add a concatenate transform named merge, using azureiotoperations/graph-dataflow-concatenate:1.0.0 from registry endpoint default. It needs no configuration.

  7. Add a destination named destination using endpoint factory-mqtt and topic factory/routed-readings.

  8. Connect source to speed-check. Drag connections from speed-check's true output to speed-path and its false output to temperature-check. Connect temperature-check's true output to temperature-path and its false output to remaining-path.

  9. Connect all three map outputs to merge, then connect merge to destination. Select Save to deploy the enabled graph.

Publish each input separately:

Input on factory/mixed-readings Output on factory/routed-readings
{"kind":"speed","value":12} {"kind":"speed","value":12,"route":"speed"}
{"kind":"temperature","value":20} {"kind":"temperature","value":20,"route":"temperature"}
{"kind":"humidity","value":60} {"kind":"humidity","value":60,"route":"remaining"}
{"value":99} {"value":99,"route":"remaining"}

Expect four separate output messages, in any order.