ExponentialBackoffRetry dynamic parameter value

Wendy Susanto 20 Reputation points
2024-01-21T09:37:03.1833333+00:00

Hi all, I'm trying to implement ExponentialBackoffRetry in one of my Azure Functions. Is there a way to retrieve the values (Max Retry, min delay, max delay) from App Settings instead of hardcoding them? Thank you

 		[FunctionName("MyFunction")]
        [ExponentialBackoffRetry(10, "00:00:45", "00:05:00")]
        public async Task Run([CosmosDBTrigger(
			/*my trigger settings here*/
		)
        {
			//my code
		}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,109 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,921 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 26,186 Reputation points
    2024-01-21T13:14:46.4666667+00:00

    Make sure that the values you want to use (Max Retry, Min Delay, Max Delay) are set in your Application Settings in the Azure Portal or your local.settings.json file during local development. 2. In your local.settings.json, it would look something like this:

       {
         "IsEncrypted": false,
         "Values": {
           "AzureWebJobsStorage": "your_storage_account_connection_string",
           "FUNCTIONS_WORKER_RUNTIME": "dotnet",
           "MaxRetry": "10",
           "MinDelay": "00:00:45",
           "MaxDelay": "00:05:00"
           // other settings if you have of course
         }
       }
    

    Then in your Azure Function, use the % syntax to reference these settings in the ExponentialBackoffRetry attribute. For example:

       [FunctionName("MyFunction")]
       [ExponentialBackoffRetry("%MaxRetry%", "%MinDelay%", "%MaxDelay%")]
       public async Task Run([CosmosDBTrigger(/*my trigger settings here*/)] ...)
       {
           // Write your code here
       }
    
    
    • %MaxRetry%, %MinDelay%, and %MaxDelay% are placeholders for the actual values in your application settings. Just extra info at runtime, AF will replace these placeholders with the corresponding values from your configuration.
    1 person found this answer helpful.

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.