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.