Durable Functions
Durable Functions let you write stateful workflows in Azure Functions. You can chain, fan out, and wait for external events in a serverless environment.
Key Capabilities
- Orchestrate complex workflows with code
- Chain and fan-out/fan-in function calls
- Wait for human interaction or external events
- Track state and progress automatically
When to Use
Use Durable Functions when you need to:
- Implement long-running workflows
- Coordinate multiple Azure Functions
- Wait for external events or approvals
Example: Orchestrator Function
- C#
- Java
- Python
[FunctionName("E1_HelloSequence")]
public static async Task<List<string>> Run(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
var outputs = new List<string>();
outputs.Add(await context.CallActivityAsync<string>("E1_SayHello", "Tokyo"));
outputs.Add(await context.CallActivityAsync<string>("E1_SayHello", "Seattle"));
outputs.Add(await context.CallActivityAsync<string>("E1_SayHello", "London"));
return outputs;
}
public class HelloSequenceOrchestrator {
@FunctionName("HelloSequence")
public List<String> run(
@OrchestrationTrigger(name = "context") DurableOrchestrationContext context) {
List<String> outputs = new ArrayList<>();
outputs.add(context.callActivity("SayHello", "Tokyo", String.class));
outputs.add(context.callActivity("SayHello", "Seattle", String.class));
outputs.add(context.callActivity("SayHello", "London", String.class));
return outputs;
}
}
def main(context):
outputs = []
outputs.append(yield context.call_activity('SayHello', 'Tokyo'))
outputs.append(yield context.call_activity('SayHello', 'Seattle'))
outputs.append(yield context.call_activity('SayHello', 'London'))
return outputs
Resources
Was this page useful?