Skip to content

Commit d41f3a2

Browse files
authored
Merge pull request #187959 from jlorich/iot-improved-details-on-message-body
improve clarity around message body and content type
2 parents c0cb63e + d94d6c4 commit d41f3a2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

articles/iot-hub/iot-hub-amqp-support.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: kgremban
55
ms.service: iot-hub
66
services: iot-hub
77
ms.topic: conceptual
8-
ms.date: 04/30/2019
8+
ms.date: 04/21/2022
99
ms.author: kgremban
1010
ms.custom: [amqp, mqtt]
1111
---
@@ -316,6 +316,8 @@ while True:
316316

317317
You can also send telemetry messages from a device by using AMQP. The device can optionally provide a dictionary of application properties, or various message properties, such as message ID.
318318

319+
To route messages based on message body, you must set the `content_type` property to be `application/json;charset=utf-8`. To learn more about routing messages either based on message properties or message body, please see the [IoT Hub message routing query syntax documentation](iot-hub-devguide-routing-query-syntax.md).
320+
319321
The following code snippet uses the [uAMQP library in Python](https://github.com/Azure/azure-uamqp-python) to send device-to-cloud messages from a device.
320322

321323
```python
@@ -331,7 +333,7 @@ msg_props = uamqp.message.MessageProperties()
331333
msg_props.message_id = str(uuid.uuid4())
332334
msg_props.creation_time = None
333335
msg_props.correlation_id = None
334-
msg_props.content_type = None
336+
msg_props.content_type = 'application/json;charset=utf-8'
335337
msg_props.reply_to_group_id = None
336338
msg_props.subject = None
337339
msg_props.user_id = None

articles/iot-hub/iot-hub-devguide-messages-construct.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ author: ash2017
55
ms.service: iot-hub
66
services: iot-hub
77
ms.topic: conceptual
8-
ms.date: 11/19/2021
8+
ms.date: 2/7/2022
99
ms.author: asrastog
1010
ms.custom: ['Role: Cloud Development', 'Role: IoT Device']
1111
---
1212

1313
# Create and read IoT Hub messages
1414

15-
To support seamless interoperability across protocols, IoT Hub defines a common message format for all device-facing protocols. This message format is used for both [device-to-cloud routing](iot-hub-devguide-messages-d2c.md) and [cloud-to-device](iot-hub-devguide-messages-c2d.md) messages.
15+
To support seamless interoperability across protocols, IoT Hub defines a common set of messaging features that are available in all device-facing protocols. These can be used in both [device-to-cloud message routing](iot-hub-devguide-messages-d2c.md) and [cloud-to-device messages](iot-hub-devguide-messages-c2d.md).
1616

1717
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-partial.md)]
1818

@@ -24,7 +24,9 @@ An IoT Hub message consists of:
2424

2525
* A set of *application properties*. A dictionary of string properties that the application can define and access, without needing to deserialize the message body. IoT Hub never modifies these properties.
2626

27-
* An opaque binary body.
27+
* A message body, which can be any type of data.
28+
29+
Each device protocol implements setting properties in different ways. Please see the related [MQTT](./iot-hub-mqtt-support.md) and [AMQP](./iot-hub-amqp-support.md) developer guides for details.
2830

2931
Property names and values can only contain ASCII alphanumeric characters, plus ``{'!', '#', '$', '%, '&', ''', '*', '+', '-', '.', '^', '_', '`', '|', '~'}`` when you send device-to-cloud messages using the HTTPS protocol or send cloud-to-device messages.
3032

@@ -42,6 +44,22 @@ Device-to-cloud messaging with IoT Hub has the following characteristics:
4244

4345
For more information about how to encode and decode messages sent using different protocols, see [Azure IoT SDKs](iot-hub-devguide-sdks.md).
4446

47+
> [!NOTE]
48+
> Each IoT Hub protocol provides a message content type property which is respected when routing data to custom endpoints. To have your data properly handled at the destination (for example, JSON being treated as a parsable string instead of Base64 encoded binary data), you must provide the appropriate content type and charset for the message.
49+
>
50+
51+
To use your message body in an IoT Hub routing query you must provide a valid JSON object for the message and set the content type property of the message to `application/json;charset=utf-8`.
52+
53+
A valid, routable message body may look like the following:
54+
55+
```json
56+
{
57+
"timestamp": "2022-02-08T20:10:46Z",
58+
"tag_name": "spindle_speed",
59+
"tag_value": 100
60+
}
61+
```
62+
4563
## System Properties of **D2C** IoT Hub messages
4664

4765
| Property | Description |User Settable?|Keyword for </br>routing query|

0 commit comments

Comments
 (0)