Skip to content

Commit

Permalink
Merge pull request MicrosoftDocs#36144 from kgremban/mar23-5346
Browse files Browse the repository at this point in the history
Clarifying routing queries for issue 5346
  • Loading branch information
PRMerger7 authored Mar 23, 2018
2 parents f572749 + e784868 commit 64fb41a
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions articles/iot-edge/module-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author: kgremban
manager: timlt

ms.author: kgremban
ms.date: 03/14/2018
ms.date: 03/23/2018
ms.topic: article
ms.service: iot-edge

Expand Down Expand Up @@ -139,32 +139,21 @@ The source specifies where the messages come from. It can be any of the followin
### Condition
The condition is optional in a route declaration. If you want to pass all messages from the sink to the source, just leave out the **WHERE** clause entirely. Or you can use the [IoT Hub query language][lnk-iothub-query] to filter for certain messages or message types that satisfy the condition.

Azure IoT messages are formatted as JSON and always have at least a **body** parameter. For example:
The messages that pass between modules in IoT Edge are formatted the same as the messages that pass between your devices and Azure IoT Hub. All messages are formatted as JSON and have **systemProperties**, **appProperties**, and **body** parameters.

```json
"message": {
"body":{
"ambient":{
"temperature": 54.3421,
"humidity": 25
},
"machine":{
"status": "running",
"temperature": 62.2214
}
},
"appProperties":{
...
}
}
```
You can build queries around all three parameters with the following syntax:

* System properties: `$<propertyName>` or `{$<propertyName>}`
* Application properties: `<propertyName>`
* Body properties: `$body.<propertyName>`

Given this sample message, there are a number of conditions that can be defined, such as:
* `WHERE $body.machine.status != "running"`
* `WHERE $body.ambient.temperature <= 60 AND $body.machine.temperature >= 60`
For examples about how to create queries for message properties, see [Device-to-cloud message routes query expressions](../iot-hub/iot-hub-devguide-query-language.md#device-to-cloud-message-routes-query-expressions).

The condition can also be used to sort message types, for example, in a gateway that wants to route messages that come in from leaf devices. Messages that come from modules contain a specific property called **connectionModuleId**. So if you want to route messages from leaf devices directly to IoT Hub, use the following route to exclude module messages:
* `FROM /messages/* WHERE NOT IS_DEFINED($connectionModuleId) INTO $upstream`
An example that is specific to IoT Edge is when you want to filter for messages that arrived at a gateway device from a leaf device. Messages that come from modules contain a system property called **connectionModuleId**. So if you want to route messages from leaf devices directly to IoT Hub, use the following route to exclude module messages:

```sql
FROM /messages/* WHERE NOT IS_DEFINED($connectionModuleId) INTO $upstream
```
### Sink
The sink defines where the messages are sent. It can be any of the following values:
Expand Down

0 comments on commit 64fb41a

Please sign in to comment.