Durable Functions - Patterns - Function chaining

Introduction

  • This is a series of articles to get our hands dirty with Durable Functions and their patterns in detail
  • Please refer to my previous article to understand the basics of durable functions
  • In this article, we will cover the Function chaining pattern

It will cover the following things,

  • Application Patterns
  • Pre-requisites
  • What is a Function chaining pattern?
  • Hands-on Lab – Create durable function using Function chaining pattern in C#
  • Hands-on Lab – Deploy a durable function using Function chaining pattern on Azure

Application patterns

The following application patterns can benefit from Durable Functions,

  • Function chaining(COVERED in this article)
  • Fan-out/fan-in
  • Async HTTP APIs
  • Monitoring
  • Human interaction
  • Aggregator (stateful entities)

Pre-requisites

These are pre-requisites to start working on durable functions,

  • An Azure pay-as-you-go account enabled
  • Install Visual Studio 2019
  • Install Azure Storage Emulator

What is a Function chaining pattern?

  • In a function chaining pattern, a sequence of functions executes in a specific order.
  • Here, the output of one function is applied to the input of another function.

Durable Functions - Patterns - Function chaining

Hands-on Lab – Create a durable function in C#

Steps to be followed,

  • Open VS 2019 and create a project
  • Choose Azure function template and create a directory

    Durable Functions - Patterns - Function chaining
     
  • Choose durable functions orchestration template

    Durable Functions - Patterns - Function chaining
     
  • Once the application has been created, we will add these functions,
     
    • Chaining
      Main functionality function which internally calls F1, F2 (with F1 result as input), F3 (with F2 result as input), F4 (with F3 result as input), return the result.
       
    • Function1_HttpStart
      Function in the form of http trigger which is responsible for initiating Chaining and gather the response.

      Durable Functions - Patterns - Function chaining
      Durable Functions - Patterns - Function chaining
  • In the above example, the values F1, F2, F3, and F4 are the names of other functions in the same function app. Code executes from the top down. The code can involve existing language control flow semantics, like conditionals and loops. You can include error handling logic in a try/catch/finally blocks.
  • Run (F5) the application and see all the functions that have been listed here,

    Durable Functions - Patterns - Function chaining
     
  • Copy the URL of Function1_HttpStart and run it in the browser,

    Durable Functions - Patterns - Function chaining
     
  • Copy the URL of statusQueryGetUri (GET URL) and run it in the browser,

    Durable Functions - Patterns - Function chaining

Here, you can see the response from Chaining which got instantiated from Function1_HttpStart with the desired output where I am capturing the output of only the last function which is dependent on the above functions, so in our case, you can see all the functions have been executed in a chain and each function output have been passed into next function.

Hands-on Lab – Deploy durable function on Azure

Steps to be followed,

  • Right-click on the function and click on publish and choose target as Azure.

    Durable Functions - Patterns - Function chaining
     
  • Choose an option as Azure function app (Windows).

    Durable Functions - Patterns - Function chaining
     
  • Create/choose the new/existing resource group and resource for azure function deployment.

    Durable Functions - Patterns - Function chaining
     
  • Click on Finish and let it get published and once published, go to the Azure portal and test the function app using the steps which we did in the above steps while creating durable functions.

This is a basic example of a Chaining pattern, where each function input is dependent on the previous function’s output.

There are multiple other patterns that represent where to use duration functions, stay tuned for the next series of articles to get a hang of it.

Happy learning!