In this post I'll run through the steps involved with creating and trying out Durable Functions in the Azure Portal. This is a great way to experiment if you don't want to (or can't) install the development environment locally.
1. Create a Function App
First you need to create a new function app in the usual way. The consumption plan is fine. In function app settings, set the runtime version to beta (I'm not sure that's required for durable functions, but I needed it in order to be offered the durable functions templates):
2. Install the Durable Functions Extension
To use durable functions we need the Durable Functions Extension, and the easiest way to do that is to create a function using one of the Durable Functions templates. Start off by clicking the
+ icon to create a new function:
If it takes you to the quickstart, choose "create your own custom function":
Choose "Durable Functions" in the "scenario" dropdown
Now you will be prompted Install the Durable Functions Extension:
It takes a few minutes to install, but once it's done we can continue to create a function using one of the Durable Functions templates.
3. Create an orchestration starter function.
Let's start off by using the HTTP Starter template, which is just a regular Azure Function that is able to kick off a new Durable Functions orchestration. I'll call mine
The sample code it generates is very generic. It lets us pass in the name of the orchestrator function as a parameter. And we can post any data that we want to send to the orchestrator in the request body. Obviously in a real-world application you'd likely have functions that specifically trigger a single orchestration.
DurableOrchestrationClient binding allows us to start a new orchestration with
StartNewAsync, and we use the helpful
CreateCheckStatusResponse function to return a JSON object containing the URIs we can use to query the status of the orchestration we've started.
4. Create an orchestrator function
We don't have any orchestrations to actually start with our starter, so let's create an orchestrator function. We'll use the orchestrator template:
I'll call it
This sample orchestration is going to call the same activity function three times, with different inputs ("Tokyo", "Seattle", "London"). The activity is called "Hello" and takes a string input.
5. Create an activity function
Next we need to create our activity function. Again there's a template for that:
But this time we must take care to name it with the name the name the orchestrator function is expecting ("Hello"):
The code for our sample activity is trivial. It takes a string and returns a string, which is fine for demo purposes. Obviously a real-world activity function would be doing something a bit more complex.
6. Start an orchestration
To test our orchestrator in the portal, we'll need to go back to our starter function We can click the "Test" tab, and put "OrchestratorFunction" in as the function name we want to call:
Now it's just a matter of clicking "Run". We'll get a
202 Accepted that gives us some JSON with information about the orchestration that was started.
In the JSON we get the id of the orchestration, plus a bunch of URIs we can use to check on the status. Something like this:
7. Query orchestration status
I just need the
statusQueryGetUri one to find out if the orchestration has completed yet and get its output. I can easily call this from powershell:
Unfortunately, I got a 404 not found! It seems like at the moment there may be a bug that causes orchestrations to intermittently fail to start. Hopefully that will be resolved soon (I've reported an issue at GitHub).
However, for the ones that did work, I was able to use the
statusQueryGetUri to retrieve details of the orchestration. Since this one runs pretty quickly, it will likely already be finished by the time you query it:
8. Looking behind the scenes
The Durable Functions extension uses an Azure Storage account behind the scenes to track the state of your orchestrations. So if you're troubleshooting issues it can be useful to know where to look to see what's been stored. You can use the excellent Azure Storage Explorer. Here's a view of the various tables, queues and blob containers that get created for a function app with the durable tasks extension. The most useful one is the
DurableFunctionsHubHistory table, which contains an "event sourced" history of all the actions that have happened in this orchestration.
For the bug I was encountering there were no records at all in the
DurableFunctionsHubHistory table the orchestration client had claimed to start. The orchestration ids are used as partition keys in the table, so it's easy to find rows relating to the orchestration instance you are interested in:
It is quite easy to try Durable Functions in the portal without having to set up any local development environment (although I do recommend that if you plan to experiment more with Durable Functions). Seems like there are still a few bugs to iron out at the moment, but I think Durable Functions is a very promising new feature that can greatly simplify the implementation of workflows in serverless environments.