Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
588 stars 740 forks source link

How to use custom retry logic by using IOTHUB_CLIENT_RETRY_NONE #2424

Closed Dasthananda closed 1 year ago

Dasthananda commented 1 year ago

We are using the azure-iot-sdk -c LTS_07_2022_Ref01 version.

we have a requirement to implement own retry logic at application layer as mentioned in https://github.com/Azure/azure-iot-sdk-c/blob/de09b35289313665f0d359835c661f8cb2a0fdf1/doc/connection_and_messaging_reliability.md

if its possible with azure-iot-sdk -c could you please provide sample code/suggestion to use the same.

I am able to set IOTHUB_CLIENT_RETRY_NONE by using IoTHubDeviceClient_SetRetryPolicy().Now retry is not happing (which is Good). Now I wanted to call this below logic .Any info on how to call sample code /suggestion to use the same. bool custom_retry_logic() { //some custom logic code. instead of default value(IOTHUB_CLIENT_RETRY_INTERVAL- 5 secs to 7secs) }.

Thanks

CIPop commented 1 year ago

This is related to #2430 : please see the answer there for the recommended way to change the retry interval to 5 or 7 seconds.

One way to implement your own custom retry logic is to add your own code within the connection status callback. Most of our samples implement the callback: https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c#L66

Please note that implementing the retry system incorrectly can cause connectivity issues for the entire device fleet due to service side quotas when devices attempt reconnecting too fast.

We have documented retry best practices in our Azure SDK for Embedded C in which the application has full control over the transport (MQTT) stack: https://github.com/Azure/azure-sdk-for-c/blob/main/sdk/docs/iot/mqtt_state_machine.md#retrying-operations