If you have played with Azure IOT Hub you might already know that there is an Azure Event hub endpoint behind the scene which takes care of message ingestion.
So your devices and backend applications use this endpoint for Cloud to device and Device to cloud communication.
In a scenario where the backend application wants to send a message to a Device and doesn’t care if the message was accepted/rejected or abandoned by the device then subscribing to the Event hub end point alone may do the trick.
But if you want feedback from IOT Hub that the message was indeed delivered and was it accepted or rejected you can subscribe to another already configured end point in Azure IOT hub which is the Feedback End point.
Let me show you the default endpoints configured in Azure IOT hub I just created:
If you see the above screenshot, there are 2 end points listed in IOT Hub:
Now the next question is how to leverage this endpoint?
Fortunately Azure IOT Hub sdks have classes that take care of this, the class is called the FeedbackReceiver class and you can instantiate it using the ServiceClient object.
var feedbackReceiver = serviceClient.GetFeedbackReceiver();
Once you have the instance of this class, you can call the ReceiveAsyn() method to loop through the feedbacks to obtain the MessageId and the Status which could be one of the following:
Finally we can let the Hub know we are done processing feedbacks by calling the CompleteAsync() method.
As you see it’s not that hard to plug in the feedback loop for cloud to device messages 🙂