You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-hub/iot-hub-devguide-messages-c2d.md
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ author: kgremban
6
6
ms.author: kgremban
7
7
ms.service: iot-hub
8
8
ms.topic: concept-article
9
-
ms.date: 12/20/2022
9
+
ms.date: 08/14/2024
10
10
ms.custom: mqtt, devx-track-azurecli
11
11
---
12
12
13
-
# Send cloud-to-device messages from an IoT hub
13
+
# Understand cloud-to-device messaging from an IoT hub
14
14
15
-
To send one-way notifications to a device app from your solution back end, send cloud-to-device messages from your IoT hub to your device. For a discussion of other cloud-to-device options supported by Azure IoT Hub, see [Cloud-to-device communications guidance](iot-hub-devguide-c2d-guidance.md).
15
+
Cloud-to-device messages are one-way notifications from your solution back end to a device application. For a discussion of other cloud-to-device options supported by Azure IoT Hub, see [Cloud-to-device communications guidance](iot-hub-devguide-c2d-guidance.md).
@@ -22,27 +22,28 @@ To target each cloud-to-device message at a single device, your IoT hub sets the
22
22
23
23
Each device queue holds, at most, 50 cloud-to-device messages. An error occurs if you try to send more messages to the same device.
24
24
25
+
This article discusses the concepts and processes around cloud-to-device messages. For guidance on developing applications that handle cloud-to-device messages, see [Send and receive cloud-to-device messages](how-to-cloud-to-device-messaging.md).
26
+
27
+
25
28
## The cloud-to-device message life cycle
26
29
27
30
To guarantee at-least-once message delivery, your IoT hub persists cloud-to-device messages in per-device queues. Devices must explicitly acknowledge *completion* of a message before the IoT hub removes the message from the queue. This approach guarantees resiliency against connectivity and device failures.
28
31
29
-
The life-cycle state graph is displayed in the following diagram:
32
+
The lifecycle state graph is displayed in the following diagram:
30
33
31
-
:::image type="content" source="./media/iot-hub-devguide-messages-c2d/lifecycle.png" alt-text="Diagram showing the life-cycle state graph of cloud-to-device messages.":::
34
+
:::image type="content" source="./media/iot-hub-devguide-messages-c2d/lifecycle.png" alt-text="Diagram showing the lifecycle state graph of cloud-to-device messages.":::
32
35
33
-
When the IoT hub service sends a message to a device, the service sets the message state to *Enqueued*. When a device wants to *receive* a message, the IoT hub *locks* the message by setting the state to *Invisible*. This state allows other threads on the device to start receiving other messages. When a device thread completes the processing of a message, it notifies the IoT hub by *completing* the message. The IoT hub then sets the state to *Completed*.
36
+
When the IoT hub service sends a message to a device, the service sets the message state to *Enqueued*. When a device thread is ready to receive a message, the IoT hub locks the message by setting the state to *Invisible*. This state allows other threads on the device to start receiving other messages. When a device thread completes the processing of a message, it notifies the IoT hub by completing the message. The IoT hub then sets the state to *Completed*.
34
37
35
38
A device can also:
36
39
37
-
**Reject* the message, which causes the IoT hub to set it to the *Dead lettered* state. Devices that connect over the Message Queuing Telemetry Transport (MQTT) protocol can't reject cloud-to-device messages.
40
+
**Reject* the message, which causes the IoT hub to set it to the *Dead lettered* state. There is no dead letter queue for recovering these messages. Devices that connect over the Message Queuing Telemetry Transport (MQTT) protocol can't reject cloud-to-device messages.
38
41
39
42
**Abandon* the message, which causes the IoT hub to put the message back in the queue, with the state set to *Enqueued*. Devices that connect over the MQTT protocol can't abandon cloud-to-device messages.
40
43
41
-
A thread could fail to process a message without notifying the IoT hub. In this case, messages automatically transition from the *Invisible* state back to the *Enqueued* state after a *visibility* time-out (or *lock* time-out). The value of this time-out is one minute and cannot be changed.
42
-
43
-
The **max delivery count** property on the IoT hub determines the maximum number of times a message can transition between the *Enqueued* and *Invisible* states. After that number of transitions, the IoT hub sets the state of the message to *Dead lettered*. Similarly, the IoT hub sets the state of a message to *Dead lettered* after its expiration time. For more information, see [Message expiration (time to live)](#message-expiration-time-to-live).
44
+
A thread could fail to process a message without notifying the IoT hub. In this case, messages automatically transition from the *Invisible* state back to the *Enqueued* state after a visibility time-out (or lock time-out). The length of this time-out is one minute and cannot be changed.
44
45
45
-
The [How to send cloud-to-device messages with IoT Hub](c2d-messaging-dotnet.md) article shows you how to send cloud-to-device messages from the cloud and receive them on a device.
46
+
The **max delivery count** property on the IoT hub determines the maximum number of times a message can transition between the *Enqueued* and *Invisible* states. After that number of transitions, the IoT hub sets the state of the message to *Dead lettered*. Similarly, the IoT hub sets the state of a message to *Dead lettered* after its expiration time.
46
47
47
48
A device ordinarily completes a cloud-to-device message when the loss of the message doesn't affect the application logic. An example of this completion might be when the device has persisted the message content locally or has successfully executed an operation. The message could also carry transient information, whose loss wouldn't impact the functionality of the application. Sometimes, for long-running tasks, you can:
48
49
@@ -137,11 +138,11 @@ Each IoT hub exposes the following configuration options for cloud-to-device mes
137
138
| feedback.maxDeliveryCount | Maximum delivery count for the feedback queue | 1 to 100; default: 10 |
138
139
| feedback.lockDurationAsIso8601 | Lock duration for the feedback queue | ISO_8601 interval from 5 to 300 seconds (minimum five seconds); default: 60 seconds. |
139
140
140
-
You can set the configuration options in one of the following ways:
141
+
You can set the configuration options in the Azure portal or Azure CLI:
141
142
142
143
***Azure portal**: Under **Hub settings** on your IoT hub, select **Built-in endpoints** and go to **Cloud to device messaging**. (Setting the **feedback.maxDeliveryCount** and **feedback.lockDurationAsIso8601** properties is not currently supported in Azure portal.)
143
144
144
-
:::image type="content" source="./media/iot-hub-devguide-messages-c2d/c2d-configuration-portal.png" alt-text="Set configuration options for cloud-to-device messaging in the portal" border="true":::
145
+
:::image type="content" source="./media/iot-hub-devguide-messages-c2d/c2d-configuration-portal.png" alt-text="Set configuration options for cloud-to-device messaging in the portal" border="true":::
145
146
146
147
***Azure CLI**: Use the [az iot hub update](/cli/azure/iot/hub#az-iot-hub-update) command:
147
148
@@ -164,6 +165,6 @@ You can set the configuration options in one of the following ways:
164
165
165
166
## Next steps
166
167
167
-
For information about the SDKs that you can use to receive cloud-to-device messages, see [Azure IoT Hub SDKs](iot-hub-devguide-sdks.md).
168
+
For information about the SDKs that you can use to handle cloud-to-device messages, see [Azure IoT Hub SDKs](iot-hub-devguide-sdks.md).
168
169
169
-
To try out receiving cloud-to-device messages, see the [Send cloud-to-device](c2d-messaging-dotnet.md) tutorial.
170
+
For guidance on developing applications that handle cloud-to-device messages, see [Send and receive cloud-to-device messages](how-to-cloud-to-device-messaging.md).
0 commit comments