Skip to content

Latest commit

 

History

History

README.md

Order processing workflow (.NET isolated)

This sample showcases an order processing workflow implemented using Durable Functions in .NET (isolated) and the Durable Task Scheduler as the storage backend provider.

You'll need:

Examine the app (optional)

The OrderProcessingOrchestration is started by an http trigger, which starts a workflow that simulates making a purchase on an e-commerce website. The orchestration consists of the following activity functions, which are found in the Activities directory:

  • ReserveInventory: This activity checks to see if there's enough inventory for the purchase
  • UpdateInventory: This activity updates the inventory count
  • NotifyCustomer: This activity sends a message to the purchaser when the purchase is successful or not successful because of insufficient inventory or failed payment processing.
  • ProcessPayment: This activity processes and authorizes the payment for the purchase

In host.json, we configure Durable Functions to use the Durable Task Scheduler:

"durableTask": {
      "storageProvider": {
        "type": "azureManaged",
        "connectionStringName": "DTS_CONNECTION_STRING"
      },
      "hubName": "%TASKHUB_NAME%"
}

Running app locally

To run the app:

  1. Add a local.settings.json file in the project root directory with the following content:

    {
        "IsEncrypted": false,
        "Values": {
            "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "DTS_CONNECTION_STRING": "Endpoint=http://localhost:8080;Authentication=None",
            "TASKHUB_NAME": "default"
        }
    }
  2. Pull the durable task scheduler emulator image from Docker and run it:

    docker pull mcr.microsoft.com/dts/dts-emulator:latest
    docker run -itP mcr.microsoft.com/dts/dts-emulator:latest
    
    docker run -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest

    Port 8080 exposes the gRPC endpoint for the durable task scheduler, and 8082 exposes the endpoint for the monitoring dashboard.

  3. Start the Azure Storage emulator Azurite in the project root directory. (This is needed for by the Function app.)

    azurite start
  4. Start the app in the project root directory.

    func start

    Expected output

    NotifyCustomer - [activityTrigger]
    
    OrderProcessingOrchestration - [orchestrationTrigger]
    
    OrderProcessingOrchestration_HttpStart - [httpTrigger]
        Invoke url: https://my-func-app.azurewebsites.net/api/orderprocessingorchestration_httpstart
    
    ProcessPayment - [activityTrigger]
    
    ReserveInventory - [activityTrigger]
    
    UpdateInventory - [activityTrigger]
    

    Note: If you encounter the error: Can't determine Project to build. Expected 1 .csproj or .fsproj but found 2:

    Delete the bin and obj directories under OrderProcessor. Try running func start again.

  5. Navigate to the OrderProcessingOrchestration_HttpStart URL. This will start an order processing orchestration instance.

  6. The HTTP call in the last step should return a list of URLs that you can use to manage the orchestration instance. You can check StatusQueryGetUri for the orchestration status. However, the durable task scheduler monitoring dashboard may be a better place to look as it provides more details about the instance.

Durable task scheduler dashboard

The dashboard comes out-of-the-box and is also available when using the emulator. Click on the 8082 port on Docker desktop, and then click on the task hub named default to see the dashboard.

Docker container ports

The dashboard gives a summary of all the orchestration instances run or running against that task hub:

Dashboard overview

Drill into an orchestration instance to see what activities were executed, duration, payload information, etc.: Orchestration instance details

The example below shows the input and output of the ReserveInventory activity: Orchestration input and output

Deploy the app to Azure

Use the Azure Developer CLI (azd) to easily deploy the app.

  1. In the root of the project, run the following command to provision and deploy the app:

    azd up
  2. When prompted, provide:

    Once the azd up command finishes, the app will have successfully provisioned and deployed. The deployment finishes with a "Run-From-Zip is set to a remote URL using WEBSITE_RUN_FROM_PACKAGE or WEBSITE_USE_ZIP app setting error. You can ignore this.

  3. After the deployment is complete, go to the portal and locate the provisioned resource group (rg-ENVIRONMENT-NAME). Click on the resource group and copy the name of the function app that was created inside it.

  4. Run the following command, replacing the placeholder with the name of your app:

    func azure functionapp list-functions <FUNCTION_APP_NAME> --show-keys

    Expected output

    NotifyCustomer - [activityTrigger]
    
    OrderProcessingOrchestration - [orchestrationTrigger]
    
    OrderProcessingOrchestration_HttpStart - [httpTrigger]
        Invoke url: https://my-func-app.azurewebsites.net/api/orderprocessingorchestration_httpstart
    
    ProcessPayment - [activityTrigger]
    
    ReserveInventory - [activityTrigger]
    
    UpdateInventory - [activityTrigger]
    
  5. Navigate to the OrderProcessingOrchestration_HttpStart URL to start an order processing orchestration instance. Use the durable task scheduler dashboard to check orchestration details.

Identity-based authentication

The durable task scheduler supports identity-based authentication only. This sample sets up the authentication through specifications in bicep files. If you're configuring identity-based access yourself, refer to documentation on Microsoft Learn.

Access dashboard after deployment

You can access the dashboard by going to https://dashboard.durabletask.io/ and registering a task hub endpoint or by following steps below to get the dashboard URL on Azure portal.

  1. Navigate to the rg-<YOUR_AZD_ENVIRONMENT_NAME> overview page on Azure portal.

  2. Select the dts-<randomGUID> resource: Provisioned resource group

  3. When on the resource overview page, select the task hub: Task hub

  4. Find the dashboard url in the top "Essentials" section: Dashboard url

Next steps

Learn more about: