In addition to Durable Functions, the Durable Task SDK for .NET can also use the durable task scheduler for managing orchestration state.
This directory includes a sample .NET console app that demonstrates how to use the scheduler with the Durable Task SDK for .NET (without any Azure Functions dependency).
- .NET 8 SDK
- Azure CLI
- Docker (for running the emulator) installed
There are two ways to run this sample locally:
The emulator simulates a scheduler and taskhub in a Docker container, making it ideal for development and learning.
-
Pull the Docker Image for the Emulator:
docker pull mcr.microsoft.com/dts/dts-emulator:latest
-
Run the Emulator:
docker run -it -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest
Wait a few seconds for the container to be ready.
-
Set the scheduler connection string:
export DURABLE_TASK_SCHEDULER_CONNECTION_STRING="Endpoint=http://localhost:8080;TaskHub=default;Authentication=None"
Local development with a deployed scheduler:
-
Install the durable task scheduler CLI extension:
az upgrade az extension add --name durabletask --allow-preview true -
Create a resource group in a region where the Durable Task Scheduler is available:
az provider show --namespace Microsoft.DurableTask --query "resourceTypes[?resourceType=='schedulers'].locations | [0]" --out tableaz group create --name my-resource-group --location <location>
-
Create a durable task scheduler resource:
az durabletask scheduler create \ --resource-group my-resource-group \ --name my-scheduler \ --ip-allowlist '["0.0.0.0/0"]' \ --sku-name "Dedicated" \ --sku-capacity 1 \ --tags "{'myattribute':'myvalue'}" -
Create a task hub within the scheduler resource:
az durabletask taskhub create \ --resource-group my-resource-group \ --scheduler-name my-scheduler \ --name "my-taskhub" -
Grant the current user permission to connect to the
my-taskhubtask hub:subscriptionId=$(az account show --query "id" -o tsv) loggedInUser=$(az account show --query "user.name" -o tsv) az role assignment create \ --assignee $loggedInUser \ --role "Durable Task Data Contributor" \ --scope "/subscriptions/$subscriptionId/resourceGroups/my-resource-group/providers/Microsoft.DurableTask/schedulers/my-scheduler/taskHubs/my-taskhub"
Note that it may take a minute for the role assignment to take effect.
-
Generate a connection string for the scheduler and task hub resources and save it to the
DURABLE_TASK_SCHEDULER_CONNECTION_STRINGenvironment variable:endpoint=$(az durabletask scheduler show \ --resource-group my-resource-group \ --name my-scheduler \ --query "properties.endpoint" \ --output tsv) taskhub="my-taskhub" export DURABLE_TASK_SCHEDULER_CONNECTION_STRING="Endpoint=$endpoint;TaskHub=$taskhub;Authentication=DefaultAzure"
The
DURABLE_TASK_SCHEDULER_CONNECTION_STRINGenvironment variable is used by the sample app to connect to the durable task scheduler resources. The type of credential to use is specified by theAuthenticationsegment. Supported values includeDefaultAzure,ManagedIdentity,WorkloadIdentity,Environment,AzureCLI, andAzurePowerShell.
Once you have set up either the emulator or deployed scheduler, follow these steps to run the sample:
-
Clone this repository.
-
Open a terminal window and navigate to the
samples/durable-task-sdks/dotnet/AspNetWebAppdirectory. -
Run the following command to build and run the sample:
dotnet run
You should see output similar to the following:
2025-01-14T22:31:10.926Z info: Microsoft.DurableTask[1] Durable Task gRPC worker starting.
2025-01-14T22:31:11.041Z info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5008
2025-01-14T22:31:11.042Z info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
2025-01-14T22:31:11.043Z info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development
2025-01-14T22:31:11.043Z info: Microsoft.Hosting.Lifetime[0] Content root path: /home/cgillum/code/github.com/Azure/Azure-Functions-Durable-Task-Scheduler-Private-Preview/samples/durable-task-sdks/dotnet/AspNetWebApp
2025-01-14T22:31:14.885Z info: Microsoft.DurableTask[4] Sidecar work-item streaming connection established.
Now, the ASP.NET Web API is running locally on your machine, and any output from the app will be displayed in the terminal window.
To run orchestrations, you can use a tool like Postman or curl in another terminal window to send a POST request to the /scenarios/hellocities?count=N endpoint, where N is the number of orchestrations to start.
curl -X POST "http://localhost:5008/scenarios/hellocities?count=10"You should then see output in the ASP.NET Web App terminal window showing the logs associated with the orchestrations that were started.
You can view the orchestrations in the Durable Task Scheduler dashboard by navigating to the scheduler-specific dashboard URL in your browser.
Use the following PowerShell command from a new terminal window to get the dashboard URL:
dashboardUrl=$(az durabletask taskhub show \
--resource-group "my-resource-group" \
--scheduler-name "my-scheduler" \
--name "my-taskhub" \
--query "properties.dashboardUrl" \
--output tsv)
echo $dashboardUrlThe URL should look something like the following:
https://dashboard.durabletask.io/subscriptions/{subscriptionID}/schedulers/my-scheduler/taskhubs/my-taskhub?endpoint=https%3a%2f%2fmy-scheduler-gvdmebc6dmdj.northcentralus.durabletask.io
Once logged in, you should see the orchestrations that were created by the sample app. Below is an example of what the dashboard might look like (note that some of the details will be different than the screenshot):
-
Create an container app following the instructions in the Azure Container App documentation.
-
During step 1, specify the deployed container app code folder at samples/durable-task-sdks/dotnet/AspNetWebApp
-
Create a user managed identity in Azure and assign the
Durable Task Data Contributorrole to it. Then attach this managed identity to the container app you created in step 1. Please use the Azure CLI or Azure Portal to set this up. For detailed instructions, see the Azure Container Apps managed identities documentation. -
Call the container app endpoint at
http://sampleapi-<your-container-app-name>.azurecontainerapps.io/scenarios/hellocities?count=10, Sample curl command:curl -X POST "https://sampleapi-<your-container-app-name>.azurecontainerapps.io/scenarios/hellocities?count=10" -
You should see the orchestration created in the Durable Task Scheduler dashboard.
