-
Notifications
You must be signed in to change notification settings - Fork 21
Add PowerShell Hello Cities sample for Durable Functions #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
greenie-msft
merged 5 commits into
Azure-Samples:main
from
hhunter-ms:add-powershell-hello-cities-v2
May 27, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f12356c
Add PowerShell Hello Cities sample for Durable Functions
hhunter-ms 0fd9f41
Potential fix for pull request finding
hhunter-ms 7bd4040
Fix review feedback: wire durableClient binding, add local.settings.j…
hhunter-ms ac875f8
Fix runtime issues: revert -DurableClient param, add HttpStatusCode t…
hhunter-ms 1912e28
Address review: idempotent type accelerator, remove Az auth, fix curl…
hhunter-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Modules/ |
9 changes: 9 additions & 0 deletions
9
samples/durable-functions/powershell/HelloCities/ChainingOrchestration/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "Context", | ||
| "type": "orchestrationTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
9 changes: 9 additions & 0 deletions
9
samples/durable-functions/powershell/HelloCities/ChainingOrchestration/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| param($Context) | ||
|
|
||
| $output = @() | ||
|
|
||
| $output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Tokyo' | ||
| $output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'Seattle' | ||
| $output += Invoke-DurableActivity -FunctionName 'SayHello' -Input 'London' | ||
|
|
||
| $output |
9 changes: 9 additions & 0 deletions
9
samples/durable-functions/powershell/HelloCities/FanOutFanInOrchestration/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "Context", | ||
| "type": "orchestrationTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
14 changes: 14 additions & 0 deletions
14
samples/durable-functions/powershell/HelloCities/FanOutFanInOrchestration/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| param($Context) | ||
|
|
||
| $cities = @('Tokyo', 'Seattle', 'London', 'Paris', 'Berlin') | ||
|
|
||
| # Fan-out: schedule all activities in parallel | ||
| $parallelTasks = @() | ||
| foreach ($city in $cities) { | ||
| $parallelTasks += Invoke-DurableActivity -FunctionName 'SayHello' -Input $city -NoWait | ||
| } | ||
|
|
||
| # Fan-in: wait for all to complete | ||
| $output = Wait-ActivityFunction -Task $parallelTasks | ||
|
|
||
| $output |
114 changes: 114 additions & 0 deletions
114
samples/durable-functions/powershell/HelloCities/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Hello Cities — Durable Functions PowerShell Quickstart | ||
|
|
||
| PowerShell | Durable Functions | ||
|
|
||
| ## Description | ||
|
|
||
| This quickstart demonstrates Durable Functions with PowerShell using the Durable Task Scheduler backend. It includes two patterns: | ||
|
|
||
| 1. **Function Chaining** — An orchestration that calls three "say hello" activities sequentially | ||
| 2. **Fan-out/Fan-in** — An orchestration that greets multiple cities in parallel and aggregates results | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. [PowerShell 7.4+](https://learn.microsoft.com/powershell/scripting/install/installing-powershell) | ||
| 2. [Azure Functions Core Tools v4](https://learn.microsoft.com/azure/azure-functions/functions-run-local) | ||
| 3. [Docker](https://www.docker.com/products/docker-desktop/) (for the emulator) | ||
|
|
||
| ## Quick Run | ||
|
|
||
| 1. Start the emulator: | ||
| ```bash | ||
| docker run -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest | ||
| ``` | ||
|
|
||
| 2. Navigate to the sample directory: | ||
| ```bash | ||
| cd samples/durable-functions/powershell/HelloCities | ||
| ``` | ||
|
|
||
| 3. Create a `local.settings.json` file: | ||
| ```json | ||
| { | ||
| "IsEncrypted": false, | ||
| "Values": { | ||
| "AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
| "FUNCTIONS_WORKER_RUNTIME": "powershell", | ||
| "DURABLE_TASK_SCHEDULER_CONNECTION_STRING": "Endpoint=http://localhost:8080;TaskHub=default;Authentication=None" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 4. Run the function app: | ||
| ```bash | ||
| func start | ||
| ``` | ||
|
|
||
| 5. Trigger the function chaining orchestration: | ||
| ```bash | ||
| curl -X POST http://localhost:7071/api/StartChaining | ||
| ``` | ||
|
|
||
| 6. Trigger the fan-out/fan-in orchestration: | ||
| ```bash | ||
| curl -X POST http://localhost:7071/api/StartFanOutFanIn | ||
| ``` | ||
|
|
||
| 7. View in the dashboard: http://localhost:8082 | ||
|
|
||
| ## Expected Output | ||
|
|
||
| The HTTP triggers return a **202 Accepted** response with status query URLs. Use the `statusQueryGetUri` from the response to poll for completion: | ||
|
|
||
| ```bash | ||
| # Replace with the statusQueryGetUri value from the 202 response | ||
| curl "<statusQueryGetUri>" | ||
| ``` | ||
|
hhunter-ms marked this conversation as resolved.
|
||
|
|
||
| Once completed, the chaining orchestration output greets Tokyo, Seattle, and London sequentially: | ||
| ```json | ||
| ["Hello Tokyo!", "Hello Seattle!", "Hello London!"] | ||
| ``` | ||
|
|
||
| The fan-out/fan-in orchestration output greets all five cities in parallel and returns combined results: | ||
| ```json | ||
| ["Hello Tokyo!", "Hello Seattle!", "Hello London!", "Hello Paris!", "Hello Berlin!"] | ||
| ``` | ||
|
hhunter-ms marked this conversation as resolved.
|
||
|
|
||
| ## Using a Deployed Scheduler (Azure) | ||
|
|
||
| To use a Durable Task Scheduler in Azure instead of the emulator: | ||
|
|
||
| 1. Update the connection string in `local.settings.json`: | ||
| ```json | ||
| { | ||
| "IsEncrypted": false, | ||
| "Values": { | ||
| "AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
| "FUNCTIONS_WORKER_RUNTIME": "powershell", | ||
| "DURABLE_TASK_SCHEDULER_CONNECTION_STRING": "Endpoint=<your-scheduler-endpoint>;TaskHub=<your-taskhub>;Authentication=ManagedIdentity" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 2. Run the sample using the same commands as above. | ||
|
|
||
| See the [Durable Task Scheduler documentation](https://learn.microsoft.com/azure/azure-functions/durable/durable-task-scheduler/develop-with-durable-task-scheduler) for setup instructions. | ||
|
|
||
| ## Code Walkthrough | ||
|
|
||
| - **SayHello/** — Activity function that returns a greeting for a given city name. | ||
| - **ChainingOrchestration/** — Orchestrator that calls `SayHello` three times in sequence. | ||
| - **FanOutFanInOrchestration/** — Orchestrator that calls `SayHello` for five cities in parallel. | ||
| - **StartChaining/** — HTTP trigger that starts the chaining orchestration. | ||
| - **StartFanOutFanIn/** — HTTP trigger that starts the fan-out/fan-in orchestration. | ||
|
|
||
| ## Viewing in the Dashboard | ||
|
|
||
| - **Emulator:** Navigate to http://localhost:8082 → select the "default" task hub | ||
| - **Azure:** Navigate to your Scheduler resource in the Azure Portal → Task Hub → Dashboard URL | ||
|
|
||
| ## Learn More | ||
|
|
||
| - [Durable Functions PowerShell Developer Guide](https://learn.microsoft.com/azure/azure-functions/durable/quickstart-powershell-vscode) | ||
| - [Durable Task Scheduler Documentation](https://aka.ms/dts-documentation) | ||
9 changes: 9 additions & 0 deletions
9
samples/durable-functions/powershell/HelloCities/SayHello/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "city", | ||
| "type": "activityTrigger", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
4 changes: 4 additions & 0 deletions
4
samples/durable-functions/powershell/HelloCities/SayHello/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| param($city) | ||
|
|
||
| Write-Host "Saying hello to $city." | ||
| "Hello $city!" |
24 changes: 24 additions & 0 deletions
24
samples/durable-functions/powershell/HelloCities/StartChaining/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "authLevel": "anonymous", | ||
| "name": "Request", | ||
| "type": "httpTrigger", | ||
| "direction": "in", | ||
| "methods": [ | ||
| "post" | ||
| ], | ||
| "route": "StartChaining" | ||
| }, | ||
| { | ||
| "name": "Response", | ||
| "type": "http", | ||
| "direction": "out" | ||
| }, | ||
| { | ||
| "name": "starter", | ||
| "type": "durableClient", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
7 changes: 7 additions & 0 deletions
7
samples/durable-functions/powershell/HelloCities/StartChaining/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| param($Request, $TriggerMetadata) | ||
|
|
||
| $instanceId = Start-DurableOrchestration -FunctionName 'ChainingOrchestration' | ||
| Write-Host "Started chaining orchestration with ID = '$instanceId'." | ||
|
|
||
| $response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $instanceId | ||
| Push-OutputBinding -Name Response -Value $response |
24 changes: 24 additions & 0 deletions
24
samples/durable-functions/powershell/HelloCities/StartFanOutFanIn/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "authLevel": "anonymous", | ||
| "name": "Request", | ||
| "type": "httpTrigger", | ||
| "direction": "in", | ||
| "methods": [ | ||
| "post" | ||
| ], | ||
| "route": "StartFanOutFanIn" | ||
| }, | ||
| { | ||
| "name": "Response", | ||
| "type": "http", | ||
| "direction": "out" | ||
| }, | ||
| { | ||
| "name": "starter", | ||
| "type": "durableClient", | ||
| "direction": "in" | ||
| } | ||
| ] | ||
| } |
7 changes: 7 additions & 0 deletions
7
samples/durable-functions/powershell/HelloCities/StartFanOutFanIn/run.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| param($Request, $TriggerMetadata) | ||
|
|
||
| $instanceId = Start-DurableOrchestration -FunctionName 'FanOutFanInOrchestration' | ||
| Write-Host "Started fan-out/fan-in orchestration with ID = '$instanceId'." | ||
|
|
||
| $response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $instanceId | ||
| Push-OutputBinding -Name Response -Value $response |
24 changes: 24 additions & 0 deletions
24
samples/durable-functions/powershell/HelloCities/host.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "version": "2.0", | ||
| "logging": { | ||
| "logLevel": { | ||
| "DurableTask.Core": "Warning" | ||
| } | ||
| }, | ||
| "extensions": { | ||
| "durableTask": { | ||
| "hubName": "default", | ||
| "storageProvider": { | ||
| "type": "azureManaged", | ||
| "connectionStringName": "DURABLE_TASK_SCHEDULER_CONNECTION_STRING" | ||
| } | ||
| } | ||
| }, | ||
| "extensionBundle": { | ||
| "id": "Microsoft.Azure.Functions.ExtensionBundle", | ||
| "version": "[4.*, 5.0.0)" | ||
| }, | ||
| "managedDependency": { | ||
| "enabled": true | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
samples/durable-functions/powershell/HelloCities/profile.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Azure Functions profile.ps1 | ||
| # | ||
| # This profile.ps1 will get executed every "cold start" of your Function App. | ||
| # "cold start" occurs when: | ||
| # | ||
| # * A Function App starts up for the very first time | ||
| # * A Function App starts up after being de-allocated due to inactivity | ||
| # | ||
| # You can define helper functions, run commands, or specify environment variables. | ||
| # NOTE: variables defined outside a function are stored in the script scope and | ||
| # are not automatically available inside your function scripts unless you | ||
| # explicitly pass them in or define them in a shared module. | ||
|
|
||
| # Register HttpStatusCode type accelerator (required by Durable Functions module) | ||
| $accelerator = [PowerShell].Assembly.GetType('System.Management.Automation.TypeAccelerators') | ||
| if (-not $accelerator::Get.ContainsKey('HttpStatusCode')) { | ||
| $accelerator::Add('HttpStatusCode', [System.Net.HttpStatusCode]) | ||
| } |
4 changes: 4 additions & 0 deletions
4
samples/durable-functions/powershell/HelloCities/requirements.psd1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @{ | ||
| # Managed dependencies - add modules here if needed | ||
| # 'Az.Accounts' = '4.*' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # PowerShell Samples for Durable Functions | ||
|
|
||
| This directory contains sample applications demonstrating Durable Functions patterns using PowerShell with the Durable Task Scheduler backend. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [PowerShell 7.4+](https://learn.microsoft.com/powershell/scripting/install/installing-powershell) | ||
| - [Azure Functions Core Tools v4](https://learn.microsoft.com/azure/azure-functions/functions-run-local) | ||
| - [Docker](https://www.docker.com/products/docker-desktop/) | ||
|
|
||
| ## Available Samples | ||
|
|
||
| | Sample | Pattern | | ||
| |--------|---------| | ||
| | [HelloCities](./HelloCities/) | Function Chaining, Fan-out/Fan-in | |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.