HypeTeq

Hypeteq-Software-logo

Azure Durable Functions

Azure Durable Funnctions
Azure Durable Functions is a programming model based on Microsoft serverless’ platform Azure Functions and therefore, has additional benefits over a standard function, such as state management, retry activities, and being able to easily cancel workflows that are still in progress. It allows you to write a workflow as code and have the execution run with the scalability and the reliability of serverless with high throughput.

Why Durable Functions?

This is very important to know, Why we should go with the Durable Functions? There is stuff that is difficult to implement with the regular Azure Function. So, here are the Durable Functions that help us to perform many activities like
  • Retry activities
  • Run activities in parallel
  • Timeout workflows
  • State management for free
  • Check on workflow progress with REST API
  • Develop and test locally
You can consider these concepts as the main components of the Durable Functions. Those play a vital role while working with the Azure Durable Function
  • Orchestrator Client
  • Orchestrator Function
  • Activity Function

Orchestrator Client

The Orchestrator client starts and stops the orchestrator functions and it takes the responsibility to monitor them.
When you are creating an HTTP triggered function initially, You can call that HTTP triggered function the Orchestrator Client. This is responsible to get the request and then it starts the orchestrator function. So this is the first step in the whole process.
The Orchestration Client is used to start the orchestrator function, and can also be used to check the status of the function, as well as terminate them.

Orchestrator Function

The Orchestrator Function plays a major role while building the Durable function and the Orchestrator Function is considered to be the heart of the durable function solution. In this function, you need to write the workflow in code. You can call the Activity function from the Orchestrator Function inside the code. You can also call another Orchestrator Function and Sub Orchestrator Function from this main Orchestrator Function.
It automatically set a checkpoint during its execution, shut itself down while waiting for other functions to finish executing, then replays through the checkpoint to resume execution.
It is important to remember how an Orchestrator function operates differently than a standard function. While a normal function only executes once per event, the orchestrator is restarted many times while waiting for other functions to complete.
This kind of behavior means that this function needs to be deterministic. It must return the same result each time. It is crucial then to not use DateTime.Now, Guid.NewGuid() or anything generating a different result in this method

Activity Function

Not every function can be used with an orchestrator. Those functions become an Activity Function when an ActivityTriggerAttribute is on a DurableActivityContext parameter.
Activity Function is called the basic unit of durable function that executes one task. You can call many activity functions inside the orchestration function. Each one of the Activity functions executes one task.
Azure Functions VS Durable Functions
The few key differences between Azure Functions and Azure Durable Functions

How To Create Durable Functions Using Visual Studio 2022

Now it will create the Project successfully. It contains 3 main files. Function1.cs file, which is the main class file that contains the Azure Function code. The next one is local.settings.json file, that is responsible to keep all the configurations that we need during the development of the project and testing the function in the local environment. The Host.json file is responsible to keep all the configuration related to your Azure Function. See below, the project created successfully with all the three files.
Below is the Azure Function code

Tagged:

SAY HELLO

Follow Us on Social Media

en_USEnglish