0 Comments Posted in:

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):

image

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:

image

If it takes you to the quickstart, choose "create your own custom function":

image

Choose "Durable Functions" in the "scenario" dropdown

image

Now you will be prompted Install the Durable Functions Extension:

image

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 HttpStarterFunction

image

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.

The 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.

image

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:

image

I'll call it OrchestratorFunction:

image

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.

image

5. Create an activity function

Next we need to create our activity function. Again there's a template for that:

image

But this time we must take care to name it with the name the name the orchestrator function is expecting ("Hello"):

image

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.

image

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:

image

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.

image

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:

{"id":"6b749f72e73443d0bc84d7bb53a6a79f",
  "statusQueryGetUri": "https://durable-functions-test.azurewebsites.net/runtime/webhooks/DurableTaskExtension/instances/6b749f72e73443d0bc84d7bb53a6a79f?taskHub=DurableFunctionsHub&connection=Storage&code=3vB2Qm8yQbWosqreTspvaSfUerCpcRaMUXiCq8rfzabcJN22R88jTQ==",
  "sendEventPostUri": "https://durable-functions-test.azurewebsites.net/runtime/webhooks/DurableTaskExtension/instances/6b749f72e73443d0bc84d7bb53a6a79f/raiseEvent/{eventName}?taskHub=DurableFunctionsHub&connection=Storage&code=3vB2Qm8yQbWosqreTspvaSfUerCpcRaMUXiCq8rfzabcJN22R88jTQ==",
  "terminatePostUri": "https://durable-functions-test.azurewebsites.net/runtime/webhooks/DurableTaskExtension/instances/6b749f72e73443d0bc84d7bb53a6a79f/terminate?reason={text}&taskHub=DurableFunctionsHub&connection=Storage&code=3vB2Qm8yQbWosqreTspvaSfUerCpcRaMUXiCq8rfzabcJN22R88jTQ=="
}

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:

Invoke-WebRequest "https://durable-functions-test.azurewebsites.net/runtime/webhooks/DurableTaskExtension/instances/6b749f72e73443d0bc84d7bb53a6a79f?taskHub=DurableFunctionsHub&connection=Storage&code=3vB2Qm8yQbWosqreTspvaSfUerCpcRaMUXiCq8rfzabcJN22R88jTQ=="

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:

{
    runtimeStatus: "Completed",
    input: null,
    output: [
        "Hello Tokyo!",
        "Hello Seattle!",
        "Hello London!"
    ],
    createdTime: "2018-01-06T11:46:23Z",
    lastUpdatedTime: "2018-01-06T11:46:28Z"
}

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.

image

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:

image

Conclusion

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.

Want to learn more about how easy it is to get up and running with Azure Functions? Be sure to check out my Pluralsight course Azure Functions Fundamentals.
Vote on HN