I have a low power hardware device that experiences frequently internet connection issues. The default DeviceClient tries for 4 minutes (240s) to reconnect to the internet and then closes with the warning "- Updating transport status to new status DISCONNECTED with reason RETRY_EXPIRED"
2023-01-10 02:17:22.654 WARN c.m.a.s.i.d.t.IotHubTransport - Updating transport status to new status DISCONNECTED with reason RETRY_EXPIRED
com.microsoft.azure.sdk.iot.device.exceptions.IotHubClientException: Device operation for reconnection timed out
at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.singleReconnectAttempt(IotHubTransport.java:1386)
at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.reconnect(IotHubTransport.java:598)
at com.microsoft.azure.sdk.iot.device.transport.IotHubReconnectTask.run(IotHubReconnectTask.java:69)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Also the attempts to reconnect are done with default ExponentialBackoffWithJitter.
c.m.a.s.i.d.t.ExponentialBackoffWithJitter - NOTE: A new instance of ExponentialBackoffWithJitter has been created with the following properties. Retry Count: 2147483647, Min Backoff Interval: 100, Max Backoff Interval: 10000, Max Time Between Retries: 100, Fast Retry Enabled: true
The default implementation tries reattempt each 10 seconds which kills the performance of the low hardware device. I would like to have a mix between occasional attempts which will detect if I have internet but does not affect performance
client = new DeviceClient(iotHubUri, deviceId, sp,IotHubClientProtocol.MQTT);
long minBackoff = 10L * 1000; //10 seconds
long maxBackoff = 10L * 60 * 1000; //10 minutes
long deltaBackoff = 100L;
RetryPolicy retryPolicy = new ExponentialBackoffWithJitter(Integer.MAX_VALUE - 1, minBackoff, maxBackoff, deltaBackoff, true);
client.setOperationTimeout(115292150000L);
client.setRetryPolicy(retryPolicy);
client.open(false);