Dmytro Seliverstov Welcome to Microsoft Q&A forum!
Apologies for the delayed response.
I am developing an application that runs on Azure Sphere and I faced an issue with my current implementation. The main problem is that SDK destroys any pending message in the queue upon disconnection. So I came to the point of implementing the mechanism of sending result verification that causes sending retrial in case of failure.
I understand that you are facing an issue with your Azure Sphere application where the SDK destroys any pending message in the queue upon disconnection.
Need your help or comments about the resending mechanism code. Is there any practice or an example of similar functionality somewhere?
Did you consider using IoTHubDeviceClient_LL_SetRetryPolicy for retry logic?
Currently the default Retry Policy in the Azure IoT Device Client C SDK is IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER (with no timeout), but it can be set by using the following SDK function:
IOTHUB_CLIENT_RESULT IoTHubClient_SetRetryPolicy( IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds);
Or if using the iothub_client_ll module:
IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy( IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds);
Note that, If retryTimeoutLimitInSeconds is set as 0 (zero) the timeout for retry policies is disabled.
See Azure IoT Device Client C SDK for more details.
To learn more about the Azure IoT device SDKs and managing retries, see Retry patterns.
You can also consider implementing a persistent storage mechanism for pending messages?
Azure IoT Hub supports several methods for storing messages, including message queues and message routing. By using one of these methods, you could ensure that no messages are lost due to disconnection. The best approach will depend on the specific requirements and constraints of your use case. See Use IoT Hub message routing to send device-to-cloud messages to different endpoints
If you need further help in this matter, please comment in the below section and we are happy to discuss!
If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.