Azure IoT Hub C2D MQTT packet subscribe issue

Vivek Karna 0 Reputation points
2023-02-21T06:28:16.2133333+00:00

Hello, community

I am having issues with subscribing to the MQTT messages from the Azure IoT hub. The scenario is that I am using a website to send a command to my MQTT client device, so when I am sending a certain JSON packet to the Azure IoT hub, then the MQTT client device subscribes that message from the Azure IoT hub and performs the operation based on the command sent to it, so for a single device, subscribing the packet is working fine. The issue is happening when there are multiples connected to the Azure IoT hub to subscribe to the packet from the Azure IoT hub. When I am using multiples web browsers to use the websites and send the command to different devices (each browser or session is sending a command to an individual MQTT client device), so, for an instance, if the commands are sent to all the devices at a same time, then none of the devices get any packet while subscribing the MQTT broker (Azure IoT hub), but if the commands are sent at 5s delay, then devices get the messages, so for each device to send command, 5s delay is necessary. Can you tell me where is the issue in the Azure IoT hub? Does Azure IoT hub not catch up with all the messages received from the website at once, does it need some delay to properly receive messages from the website?

Please help.

Thanks,
Vivek Karna

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,272 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 35,971 Reputation points Moderator
    2023-02-21T08:16:38.76+00:00

    Vivek Karna Welcome to Microsoft Q&A forum! That's a great question.
    Please see the below information which will help you understand more about MQTT support.

    The issue is happening when there are multiples connected to the Azure IoT hub to subscribe to the packet from the Azure IoT hub.

    IoT Hub isn't a full-featured MQTT broker and doesn't support all the behaviors specified in the MQTT v3.1.1 standard. Based on the information you provided, it is possible that the issue you are experiencing is related to the QoS (Quality of Service) level used in your MQTT communication. QoS is a parameter that defines the guarantee of message delivery between MQTT client devices and the broker.

    When I am using multiples web browsers to use the websites and send the command to different devices (each browser or session is sending a command to an individual MQTT client device), so, for an instance, if the commands are sent to all the devices at a same time, then none of the devices get any packet while subscribing the MQTT broker (Azure IoT hub), but if the commands are sent at 5s delay, then devices get the messages, so for each device to send command, 5s delay is necessary.

    User's image

    Note that, Azure IoT Hub only supports one active MQTT connection per device. If a new MQTT connection is made on behalf of the same device ID, the existing connection will be dropped and a 400027 ConnectionForcefullyClosedOnNewConnection will be logged into the IoT Hub Logs.

    To receive messages from IoT Hub, a device should subscribe using devices/{device-id}/messages/devicebound/# as a Topic Filter.

    The device doesn't receive any messages from IoT Hub until it has successfully subscribed to its device-specific endpoint, represented by the devices/{device-id}/messages/devicebound/# topic filter.

    After a subscription has been established, the device receives cloud-to-device messages that were sent to it after the time of the subscription. If the device connects with CleanSession flag set to 0, the subscription is persisted across different sessions. If the device uses CleanSession flag set to 1, it doesn't receive any messages from IoT Hub until it subscribes to its device-endpoint.

    For more details, please see Communicate with your IoT hub using the MQTT protocol and Choose a device communication protocol.

    so, for an instance, if the commands are sent to all the devices at a same time, then none of the devices get any packet while subscribing the MQTT broker (Azure IoT hub), but if the commands are sent at 5s delay, then devices get the messages, so for each device to send command, 5s delay is necessary. Can you tell me where is the issue in the Azure IoT hub? Does Azure IoT hub not catch up with all the messages received from the website at once, does it need some delay to properly receive messages from the website?

    It seems that the issue is happening because of the multiple devices trying to subscribe to the same message at the same time. To resolve this issue, As you have already mentioned, you can try to implement a delay between the devices to subscribe to the messages.

    Also, see IoT Hub MQTT 5 support overview (preview)

    Hope this information helps you to understand more about the MQTT support.

    Do let us know if you have any further queries. We would be happy to assist you.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.