Retry mechanism in IoT Edge

Satyam Chauhan 547 Reputation points
2024-01-23T12:14:55.8333333+00:00

Hi, I have setup IoT Edge runtime on an on-premise server. The device to cloud connectivity is through site-to-site VPN. I have created custom IoT Edge modules using .net SDK, and the modules are working fine and sending the device to cloud messages. I want to know how the retry mechanism work here in case of any disconnectivity or device/message throttling. I have not added any thing explicitly to handle the retry process. Does modules developed using .net sdk support retry mechanism by default or we have to explicitly write some code to handle it. Please let me know how is it done.

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
576 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 15,886 Reputation points Microsoft Employee
    2024-01-23T17:57:39.37+00:00

    Hi @Satyam Chauhan Thank you for posting the question here. The IoT Edge modules use Azure IoT device SDKs and connect to the IoT Edge Hub locally the same way an IoT device connects to IoT Hub. Connection failures with the devices can happen due to Network errors, protocol issues or Application-level errors. The device SDKs are equipped to detect errors at all three levels. However, device SDKs don't detect and handle OS-related errors and hardware errors.

    Retry patterns

    The SDKs typically provide three retry policies:

    • Exponential back-off with jitter: This default retry policy tends to be aggressive at the start and slow down over time until it reaches a maximum delay.
    • Custom retry: For some SDK languages, you can design a custom retry policy that is better suited for your scenario and then inject it into the RetryPolicy.
    • No retry: You can set retry policy to "no retry", which disables the retry logic. The SDK tries to connect once and send a message once, assuming the connection is established.

    The SDK uses Exponential back-off with jitter retry policy by default.

    You can set your own Custom Retry Policy to the Device Client by implementing the IRetryPolicy interface such as shown below.

    public class MyCustomRetryPolicy : IRetryPolicy
    {
        /// <summary>
        /// Returns true if, based on the parameters, the operation should be retried.
        /// </summary>
        /// <param name="currentRetryCount">How many times the operation has been retried.</param>
        /// <param name="lastException">Operation exception.</param>
        /// <param name="retryInterval">Next retry should be performed after this time interval.</param>
        /// <returns>True if the operation should be retried, false otherwise.</returns>
        public bool ShouldRetry(int currentRetryCount, Exception lastException, out TimeSpan retryInterval)
        {
            // Implement your retry strategy here
        }
    }
    
    deviceClient.SetRetryPolicy(new MyCustomRetryPolicy(...));
    

    Here is a reference to a couple of articles if you are interested in getting more information on this.

    Hope this answers your questions. Please let us know if you need any additional assistance on this.


    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.


0 additional answers

Sort by: Most helpful

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.