This sample demonstrates the function chaining pattern with the Azure Durable Task Scheduler using the JavaScript SDK. Function chaining is a fundamental workflow pattern where activities are executed in a sequence, with the output of one activity passed as the input to the next activity.
In this sample:
- The orchestrator calls the
sayHelloactivity with a name input. - The result is passed to the
processGreetingactivity. - That result is passed to the
finalizeResponseactivity. - The final result is returned to the client.
This pattern is useful for:
- Creating sequential workflows where steps must execute in order
- Passing data between steps with data transformations at each step
- Building pipelines where each activity adds value to the result
- Node.js 22+
- Docker (for running the emulator) installed
- Azure CLI (if using a deployed Durable Task Scheduler)
- Azure Developer CLI
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 --name dtsemulator -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest
Wait a few seconds for the container to be ready.
Note: The sample code automatically uses the default emulator settings (endpoint: http://localhost:8080, taskhub: default). You don't need to set any environment variables.
-
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 table az 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 -
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"
-
Set environment variables in each terminal where you run the worker or client:
export ENDPOINT=$(az durabletask scheduler show \ --resource-group my-resource-group \ --name my-scheduler \ --query "properties.endpoint" \ --output tsv) export TASKHUB="my-taskhub"
Once you have set up either the emulator or deployed scheduler, follow these steps to run the sample:
-
Navigate to this sample directory:
cd samples/durable-task-sdks/javascript/function-chaining -
Install dependencies:
npm install
-
Start the worker in a terminal:
npm run worker
-
In a new terminal, run the client:
npm run client
You can optionally provide a base name:
npm run client -- Alice
The client schedules 20 orchestrations, one every 5 seconds, then waits for all of them to complete.
This sample includes an azure.yaml configuration file that allows you to deploy the entire solution to Azure using Azure Developer CLI (AZD).
Note: This sample uses the shared infrastructure templates located at
samples/infra/.
-
Authenticate with Azure:
azd auth login
-
Navigate to the Function Chaining sample directory:
cd samples/durable-task-sdks/javascript/function-chaining -
Initialize the Azure Developer CLI project (only needed the first time):
azd init
-
Provision resources and deploy the application:
azd up
This command provisions Azure resources (including Azure Container Apps and Durable Task Scheduler), builds and deploys both the client and worker, and sets up the required environment configuration.
- In the Azure portal, open the resource group created by
azd up. - Open the
clientcontainer app and select Monitoring > Log stream. - Confirm orchestrations are being scheduled and completed.
- Open the
workercontainer app and select Monitoring > Log stream. - Confirm activities are being executed in order.
To inspect orchestration history:
- Local emulator: open
http://localhost:8082and select thedefaulttask hub. - Deployed scheduler: open the task hub dashboard URL from your scheduler resource in Azure.
The dashboard shows the sequence of activities and input/output transitions for each orchestration instance.