Structure Topic Mqtt Iot Hub

Eduardo Guido Flores Pascual 1 Reputation point
2022-10-13T00:33:04.647+00:00

Hello! , I have a question, I know the structure for the topic is "devices/DEVICE_ID/messages/events", without TOPIC, at least it is in the docummention https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support, but the tests that were done by @Red255 in another question tells us that we can use an extra word in the topic structure, it means the topic structure would be " devices/DEViCE_ID/messages/events/TOPIC".
could you confirm this information? Because if this is correct, the docummentation should be updated.

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

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 36,761 Reputation points MVP Volunteer Moderator
    2022-10-13T15:49:44.42+00:00

    Hello @Eduardo Guido Flores Pascual ,

    you want confirmation about the right topic for non-SDK MQTT communication to the Azure IoT HUb.

    I used plain C# to describe the topic interaction workflow.

    There I used this solution:

    public string send_message_topic => $"devices/{_clientId}/messages/events/";  
    
    var message = new MqttApplicationMessageBuilder()  
                   .WithTopic(topics.send_message_topic + "$.ct=application%2Fjson&$.ce=utf-8" + "&a=a1&b=bb2")  
                   .WithPayload(payloadString)  
                   .WithQualityOfServiceLevel(MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce)  
                   .Build();  
    
    await mqttClient.PublishAsync(message);  
    

    As you can see, several user properties can be sent along using string concatenation.

    I wrote this blog post about the concept a couple of months ago.

    See also this GitHub repo.


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.