Get Azure Durable Functions running in Azure Portal for 5 minutes

Hello All,

Azure Durable Functions provides unique way to orchestrate Azure Functions via code and implement advanced workflows leveraging long running executions as well as persisting local state.

In Azure Durable Functions documentation you can find great reference how to use Visual Studio for development.

In recent post we covered how to use Visual Studio Code to develop Azure Durable Functions on Windows, Mac and Linux.

In this post we will see how to get Azure Durable Functions up and running in less than 5 minutes in Azure Portal!

We will utilize already configured templates in Azure Portal and we will build an application containing 3 types of functions:

  • Orchestrator Client
  • Orchestrator
  • Activity

We will use the following architecture:

ArchitectureV2

 

Mobile Client or any RESTful client will call the orchestrator client to trigger the execution. The orchestrator client will start the orchestrator function that will call an activity function multiple times. In the end we will check the output via “statusQueryGetUri” endpoint exposed by the orchestration client.

So, let’s start and keep eye on the time – we will be done in less than 5 minutes!

  • Let’s access Azure Portal and find Function App

1

  • Let’s fill the necessary data for Functions App

2

  • Azure Durable Functions requires to run on the preview version of the Runtime. So let’s change that via Function Settings

3

  • And then let’s select “beta” for runtime version

4.PNG

  • Now let’s create our first function. Please select “Create your own custom function”

5

  • On the following screen change Scenario to “All” and select DurableFunctionsHttpStart

6

  • You need to install the extension required for Azure Durable Functions

7

  • Please press “Install” and you will get the following message. The installation is actually faster than 10 minutes so we are still on track to meet our deadline:

8

  • After the install is complete, we are ready to create our first function – “HttpStart” that is of type Orchestration Client and is created by selecting DurableFunctionsHttpStart template

9

The function is responsible for managing the orchestrator function requested by the user:

 
#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
#r "Newtonsoft.Json"

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req,
DurableOrchestrationClient starter, string functionName, TraceWriter log)
{
  // Function input comes from the request content.
  dynamic eventData = await req.Content.ReadAsAsync<object>();
  string instanceId = await starter.StartNewAsync(functionName, eventData);

  log.Info($"Started orchestration with ID = '{instanceId}'.");

  return starter.CreateCheckStatusResponse(req, instanceId);
}

with configuration:


{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": [
"post",
"get"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
],
"disabled": false
}

  • Now, let’s create our orchestration function “HelloSequence” from “DurableFunctionOrchestrator” template

10

This is our orchestrator function that will call 3 times the Activity function:


/*
 * Before running this sample, please create a Durable Activity function (default name is "hello")
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"

public static async Task<List<string>> Run(DurableOrchestrationContext context)
{
 var outputs = new List<string>();

// Replace "hello" with the name of your Durable Activity Function.
 outputs.Add(await context.CallActivityAsync<string>("Hello", "Tokyo"));
 outputs.Add(await context.CallActivityAsync<string>("Hello", "Seattle"));
 outputs.Add(await context.CallActivityAsync<string>("Hello", "London"));

// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
 return outputs;
}

And we apply the following configuration:


{
 "bindings": [
 {
 "name": "context",
 "type": "orchestrationTrigger",
 "direction": "in"
 }
 ],
 "disabled": false
}

  • And our last function will be “Hello” from “DurableFunctionActivity” template

11

This is function that actually will perform the actual “work”:


/*
 * Before running this sample, please create a Durable Activity function (default name is "hello")
 */

#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"

public static string Run(string name)
{
 return $"Hello {name}!";
}

And we use the following configuration for the this function:


{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
],
"disabled": false
}

  • Now let’s go to HttpStart function and copy its URL

12

  • Let’s use Postman or cURL to query the endpoint. No data is required to be passed just use POST verb

13

  • Then let’s call the “statusQueryGetUri” endpoint and we will see the actual output of the Durable Function

15

  • Congratulations! Your first Azure Durable Functions is up and running in Azure Portal!!!

 

Congratulations! Now you can run Azure Durable Functions in Visual Studio, Visual Studio Code on Mac and Linux and in this post we learn how to use Azure Portal for Azure Durable Functions development!

Azure Durable Functions Everywhere! 

Thank you!

Kanio

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s