Saturday, 15 September 2018

Create Azure Durable Functions which includes Orchestrator Function and Activity Function - Part 1

In this post we are going to see how to create a Azure Durable Functions that includes the Orchestrator Function and Activity Function.

Azure Durable Functions is a new model based on Serverless platform Azure Functions. It allows you to write the workflow as code. It introduces more concepts that make developing complex workflow easy.

Azure Functions allows you to pay for what you use. A Serverless function is a unit of work which consists of a method from a static class.


public static class TestFunction
{
    [FunctionName("FirstFunction")]
    public void FirstFunction()
    {
       
    }

}


Orchestrator Function:
**********************************
An Orchestrator is an Azure function with specific behavior attached to them. it automatically set the checkpoint during its execution. Orchestrator Function is a function with an OrchestrationTrigger  on a DurableOrchestrationContext parameter.


[FunctionName("Orchestrator")]
public static async Task Orchestrator([OrchestrationTrigger] DurableOrchestrationContext context)
{
    return context.InstanceId;

}


It is invoked by DurableOrchestrationClient decorated by OrchestrationClient Attribute injected with in the ordinary function with any trigger.

[FunctionName("TimerTrigger")]
public static void TimerTrigger([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, [OrchestrationClient]DurableOrchestrationClient starter)
{
    // Function input comes from the request content.
    string instanceId = await starter.StartNewAsync("Orchestrator", null);
    /* ... */

}


Activity Function
************************
Not every function will be used with an orchestrator function, only ActivityFunction which are decorated by ActivityTrigger with DurableActivityContext parameter can be used inside Orchestration Function

[FunctionName("Activity1")]
public static async Task<string> Activity([ActivityTrigger] DurableActivityContext context)
{
    /* ... */

}


Calling the Activity function "Activity1" inside the Orchestrator Function

[FunctionName("Orchestrator")]
public static async Task Orchestrator([OrchestrationTrigger] DurableOrchestrationContext context)
{
    await context.CallActivityAsync<string>("Activity1", name);
    return context.InstanceId;

}




From this post you can learn more about Azure Durable Function which includes Orchestrator Function and Activity Function. we will see the implementation of this Durable Function in the Part 2 of this post

































No comments:

Post a Comment