问题
I used the python example from https://docs.microsoft.com/de-de/azure/iot-hub/quickstart-send-telemetry-python to send telemetry data to the IoTHub. Now I try to forward only the messages from the device "test-device" into a blob storage via a custom endpoint and a route. With the query string "true" all messages from all devices are pushed to the storage. However, I don't get the query to select only the messages from the deviceId "test-device". I search in the documentation but didn't find any helpful example...
Can anyone help me with the query? At least it would be also helpful to sample incoming messages inside the IoTHub to get an idea of the structure of IotHub messages (like it is done in the StreamAnalytics "sample data").
回答1:
You can try to use $connectionDeviceId = "{your device id}"
in the route query. connectionDeviceId
is stamped on servicebound messages by the IoT Hub. I think it is simpler than silent's suggestion. Message system properties are prefixed with the '$' symbol. More query language for message routing here.
回答2:
There is a very good blog post on message routing here.
You can for example route on any properties you add to your messages or on any field inside your message body (if it is UTF-8 encoded JSON). Not sure if you can by default route on deviceId, but you could for example add a property "testmessage": true
to your messages and then have a routing rule to match that:
"testmessage" = true
来源:https://stackoverflow.com/questions/51153543/azure-iothub-devicemessage-structure-and-route-query