403004 DeviceMaximumQueueDepthExceeded403004 DeviceMaximumQueueDepthExceeded

本文介绍 403004 DeviceMaximumQueueDepthExceeded 错误的原因和解决方案。This article describes the causes and solutions for 403004 DeviceMaximumQueueDepthExceeded errors.

症状Symptoms

尝试发送云到设备的消息时,请求失败,并出现错误 403004DeviceMaximumQueueDepthExceededWhen trying to send a cloud-to-device message, the request fails with the error 403004 or DeviceMaximumQueueDepthExceeded.

原因Cause

根本原因是,设备的已排队消息数超出队列限制 (50)The underlying cause is that the number of messages enqueued for the device exceeds the queue limit (50).

遇到此限制最可能的原因是你在使用 HTTPS 接收消息,这会导致使用 ReceiveAsync 进行持续轮询,从而导致 IoT 中心限制请求。The most likely reason that you're running into this limit is because you're using HTTPS to receive the message, which leads to continuous polling using ReceiveAsync, resulting in IoT Hub throttling the request.

解决方案Solution

使用 HTTPS 的云到设备消息,其支持模式是间歇连接到设备,且不常检查消息(时间间隔小于 25 分钟)。The supported pattern for cloud-to-device messages with HTTPS is intermittently connected devices that check for messages infrequently (less than every 25 minutes). 若要降低遇到队列限制的可能性,请切换到 AMQP 或 MQTT(针对云到设备的消息)。To reduce the likelihood of running into the queue limit, switch to AMQP or MQTT for cloud-to-device messages.

也可增强设备端的逻辑,以便快速完成、拒绝或放弃排队的消息,缩短生存时间,或者考虑发送较少的消息。Alternatively, enhance device side logic to complete, reject, or abandon queued messages quickly, shorten the time to live, or consider sending fewer messages. 请参阅 C2D 消息的生存时间See C2D message time to live.

最后,请考虑使用清除队列 API,在达到限制之前定期清除挂起的消息。Lastly, consider using the Purge Queue API to periodically clean up pending messages before the limit is reached.