Hi @Dhanavath Vishnu Greetings! Thank you for posting the question here.
All cloud-to-device messages get queued in per-device queues to guarantee at-least-once message delivery. Once the devices send an acknowledgment message to the IoT Hub indicating that the message reception is complete, then the IoT Hub removes the messages from the queue. If the device fails to receive the message, they end up either in the Dead lettered state or Enqueued state based on why the message reception by the device failed. Please find the below image to understand how the cloud to device message live cycle works.
You can get more information on this from the article section - The cloud-to-device message life cycle
We can access these status state of the message by using the Feedback receiver method provided on the SDK. The Receive delivery feedback section of the article provides the implementation of this method and how to use it to receive the message received acknowledgement status from the device. Below is the method for your reference.
private async static void ReceiveFeedbackAsync()
{
var feedbackReceiver = serviceClient.GetFeedbackReceiver();
Console.WriteLine("\nReceiving c2d feedback from service");
while (true)
{
var feedbackBatch = await feedbackReceiver.ReceiveAsync();
if (feedbackBatch == null) continue;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Received feedback: {0}",
string.Join(", ", feedbackBatch.Records.Select(f => f.StatusCode)));
Console.ResetColor();
await feedbackReceiver.CompleteAsync(feedbackBatch);
}
}
Based on the status code returned from the messages, you can use this approach to differentiate between the messages that get delivered and those that stay in the queue. You can store the messages filtered based on this conditioning and store it at any end point of your choice for later comparision.
Hope this helps! Please let us know if you have any additional questions.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.