Durable Functions is an offering as part of Azure Functions to develop stateful applications. If you have been developing micro-services which are stateful then durable functions would be the apt choice to consider.
Today in this post , we will walk through durable functions using Function chaining pattern. In this sample , we will be developing a durable function which performs three activities in order. I have used the sample as part of CodePaLOUsa and Boston Code Camp sessions.
If you are a developer using BizTalk Server you might be aware of the term Orchestration. Similar concept is used in Azure Durable Function as Orchestration. An orchestration is a work flow which can perform multiple activities. You would require a Orchestration client to invoke the orchestration. In the sample we are using HTTP based orchestration client.
The complete code sample for this example can be found in the below Git repository
In the sample here, we have the Orchestration client which is invoked through Http. The code for Orchestration Client is part of HttpStart.cs.
This function takes in a Http Request and defines a Durable Orchestration Client and invokes the function “OrderProcessingSequence” which is our Orchestration.
Below url is used to invoke the Orchestration.
On debugging the solution by providing appropriate values for these two configuration values in local.settings.json (“AzureWebJobsStorage” and “AzureWebJobsDashboard”), we can observe the following changes which takes place in azure for the given storage account.
On exploring the blobs we can see new containers getting created one specific for regular azure web job hosts and other for durable functions hub leases.
Further exploring the Queues under the storage account, we could see the below queues getting created in the background. In the Durable functions sample we have three activities. Out of the five queues which got created, my guess is that one is specific to the orchestration and three queues for three activities and as the name suggests the other queue is used when durable function runtime is working on a specific item.
When we explore the Table Service under the storage account, we could see the below table getting created. This is used to maintain the state of the application and query the status of the application.
When invoking the orchestration using PostMan, we get three urls one is used to query the status of the request using “statusQueryGetUri” and other is to post events to orchestration using “sendEventPostUri” and other is to terminate the instance of orchestration using “terminatePostUri”. These urls are used to manage the state of the durable function.
In the example above , we have posted the email address with blank value. The third activity which processes and sends email, exception is thrown when there is no email address provided as part of the input request. We can find the status of the above request using statusQueryGetUri.
If the orchestration is executed successfully the run time status will be Completed and we can find both input and output using statusQueryGetUri.
In my next blog we will be exploring sending events and developing timer activities using durable functions.
Thanks to Azure Functions team for publishing the below durable functions sample, which I have used to develop the following example.