{"id":17593711,"url":"https://github.com/azure-samples/durable-functions-order-processing","last_synced_at":"2025-04-12T09:12:33.574Z","repository":{"id":258380968,"uuid":"871357170","full_name":"Azure-Samples/Durable-Functions-Order-Processing","owner":"Azure-Samples","description":"This repository contains the implementation of an order processing workflow with Durable Functions in C#. The sample is deployed to Azure Functions Flex Consumption using the Azure Developer CLI (azd) and is configured with managed identity as the authentication mechanism. ","archived":false,"fork":false,"pushed_at":"2024-11-05T01:03:06.000Z","size":265,"stargazers_count":2,"open_issues_count":0,"forks_count":8,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-12T09:11:22.165Z","etag":null,"topics":["azd","azd-templates","azure","azure-function","azure-functions","bicep","csharp","dotnet","durable-functions","managedidentity","msft","new"],"latest_commit_sha":null,"homepage":"","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure-Samples.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-11T19:42:28.000Z","updated_at":"2025-01-02T19:28:12.000Z","dependencies_parsed_at":"2025-04-12T09:11:25.513Z","dependency_job_id":null,"html_url":"https://github.com/Azure-Samples/Durable-Functions-Order-Processing","commit_stats":null,"previous_names":["azure-samples/durable-functions-order-processing"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2FDurable-Functions-Order-Processing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2FDurable-Functions-Order-Processing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2FDurable-Functions-Order-Processing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2FDurable-Functions-Order-Processing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/Durable-Functions-Order-Processing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543848,"owners_count":21121838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azd","azd-templates","azure","azure-function","azure-functions","bicep","csharp","dotnet","durable-functions","managedidentity","msft","new"],"created_at":"2024-10-22T06:12:37.165Z","updated_at":"2025-04-12T09:12:33.552Z","avatar_url":"https://github.com/Azure-Samples.png","language":"Bicep","readme":"\u003c!--\n---\ndescription: This end-to-end sample shows how implement an order processing workflow using Durable Functions. \npage_type: sample\nproducts:\n- azure-functions\n- azure\nurlFragment: durable-func-order-processing\nlanguages:\n- csharp\n- bicep\n- azdeveloper\n---\n--\u003e\n\n# Order processing workflow with Durable Functions\n\n[Azure Functions](https://learn.microsoft.com/azure/azure-functions/functions-overview) has an extension called [Durable Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview). Durable Functions helps you easily orchestrate stateful logic, making it an excellent solution for workflow scenarios, as well as stateful patterns like fan-out/fan-in and workloads that require long-running operations or need to wait arbitrarily long for external events. \n\nThis sample shows how to implement an order processing workflow with Durable Functions in C# (running in the isolated model) and can easily be deployed to a function app in Azure. Durable Functions needs a [\"storage backend provider\"](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-storage-providers) to persist application states. This sample uses the default backend, which is Azure Storage.  \n\n\u003e [!IMPORTANT]\n\u003e This sample creates several resources. Make sure to delete the resource group after testing to minimize charges!\n\n## Run in your local environment\n\nThe project is designed to run on your local computer, provided you have met the [required prerequisites](#prerequisites). You can run the project locally in these environments:\n\n+ [Using Azure Functions Core Tools (CLI)](#using-azure-functions-core-tools-cli)\n+ [Using Visual Studio](#using-visual-studio)\n+ [Using Visual Studio Code](#using-visual-studio-code)\n\n### Prerequisites\n\n+ [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) \n+ [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local?tabs=v4%2Cmacos%2Ccsharp%2Cportal%2Cbash#install-the-azure-functions-core-tools)\n+ Start Azurite storage emulator. See [this page](https://learn.microsoft.com/azure/storage/common/storage-use-azurite) for how to configure and start the Azurite emulator for Local Storage.\n+ Clone the repo, then create a file named `local.settings.json` with the following content in the **OrderProcessor** directory:\n\n  ```json\n  {\n    \"IsEncrypted\": false,\n    \"Values\": {\n      \"AzureWebJobsStorage\": \"UseDevelopmentStorage=true\",\n      \"FUNCTIONS_WORKER_RUNTIME\": \"dotnet-isolated\"\n    }\n  }\n  ```\n\n### Using Azure Functions Core Tools (CLI)\n\n1) Open a new terminal and do the following:\n\n```bash\ncd OrderProcessor\nfunc start\n```\n\n2) This sample uses an HTTP trigger to start an orchestration, so open a browser and go to http://localhost:7071/api/OrderProcessingOrchestration_HttpStart. You should see something similar to the following: \n\n```json\n{\n    \"id\": \"e838bdb52db24560a6b30c261ac2985d\",\n    \"purgeHistoryDeleteUri\": \"http://localhost:7071/runtime/webhooks/durabletask/instances/e838bdb52db24560a6b30c261ac2985d?code=\u003ccode\u003e\",\n    \"sendEventPostUri\": \"http://localhost:7071/runtime/webhooks/durabletask/instances/e838bdb52db24560a6b30c261ac2985d/raiseEvent/{eventName}?code=\u003ccode\u003e\",\n    \"statusQueryGetUri\": \"http://localhost:7071/runtime/webhooks/durabletask/instances/e838bdb52db24560a6b30c261ac2985d?code=\u003ccode\u003e\",\n    \"terminatePostUri\": \"http://localhost:7071/runtime/webhooks/durabletask/instances/e838bdb52db24560a6b30c261ac2985d/terminate?reason={{text}}}\u0026code=\u003ccode\u003e\"\n}\n```\n\n3) To check the status of the orchestration instance started, go to the `statusQueryGetUri`. Your orchestration instance should show status \"Running\". After a few seconds, refresh to see that the orchestration instance is \"Completed\" and what the output is.\n\n```json\n{\n    \"name\": \"OrderProcessingOrchestration\",\n    \"instanceId\": \"e838bdb52db24560a6b30c261ac2985d\",\n    \"runtimeStatus\": \"Completed\",\n    \"input\": {\n        \"Name\": \"milk\",\n        \"TotalCost\": 5,\n        \"Quantity\": 1\n    },\n    \"customStatus\": null,\n    \"output\": {\n        \"Processed\": true\n    },\n    \"createdTime\": \"2024-09-12T00:29:07Z\",\n    \"lastUpdatedTime\": \"2024-09-12T00:29:31Z\"\n}\n```\n\n### Using Visual Studio\n\n1) Open project using Visual Studio 2022 or later.\n2) Press Run/F5 to run in the debugger\n3) Use same approach above to start an orchestration instance and check its status. \n\n### Using Visual Studio Code\n\n1) Open this folder in a new terminal\n2) Open VS Code by entering `code .` in the terminal\n3) Press Run/Debug (F5) to run in the debugger\n4) Use same approach above to start an orchestration instance and check its status. \n\n\n## Provision the solution on Azure\n\nIn the root folder (Durable-Functions-Order-Processing) use the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd?tabs=winget-windows%2Cbrew-mac%2Cscript-linux\u0026pivots=os-windows) to provision a new resource group with the environment name you provide and all the resources for the sample by running:\n\n```bash\nazd up\n``` \n\n## Inspect the solution (optional)\n\nOnce the deployment is done, inspect the new resource group. The Flex Consumption function app and plan, storage, App Insights, and networking related resources have been created and configured:\n![Screenshot of resources created by the bicept template](./img/resources-created.png)\n\nBecause Durable Functions requires access to Azure Storage Blob, Table, and Queue, the associated networking resources such as private endpoints, link, etc. are created for each of those. \n\nFlex Consumption has an *[always ready](https://learn.microsoft.com/azure/azure-functions/flex-consumption-how-to?#set-always-ready-instance-counts)* feature that allows users to specify the number of compute instances that are always running to minimize cold start. This sample [sets always ready instance](https://learn.microsoft.com/azure/azure-functions/flex-consumption-plan#considerations) to 1 for the \"durable\" group.  \n\nThe property [`maxQueuePollingInterval`](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-bindings#hostjson-settings) is also set to 1 second to decrease message processing latencies. Note, however, that lower values of `maxQueuePollingInterval` can result in higher storage costs because of increased storage transactions.\n\n## Test the solution\n\n1. Use this Function CLI command to quickly find the function app url:\n\n    ```bash\n    func azure functionapp list-functions \u003cAPP_NAME\u003e --show-keys\n    ````\n    \n    The url should look something like this: https://func-processor-abcdefgxzy.azurewebsites.net/api/OrderProcessingOrchestration_HttpStart. \n\n2. Open up a browser and go that url to trigger the start of an orchestration instance. \n\n3. Go to the `statusQueryGetUri` to see the status of your orchestration instance. It should show \"Running\" at the beginning, but change to \"Completed\" after a few seconds if you refresh the page, just like shown [above](#using-azure-functions-core-tools-cli). \n\n## Clean up resources\n\nWhen you no longer need the resources created in this sample, run the following command to delete the Azure resources:\n\n```bash\nazd down\n```\n\n## Resources\n\nFor more information on Durable Functions, the new Flex Consumption plan, and VNet integration, see the following resources:\n\n* [Durable Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview)\n* [Azure Functions Flex Consumption documentation](https://learn.microsoft.com/azure/azure-functions/flex-consumption-plan)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fdurable-functions-order-processing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure-samples%2Fdurable-functions-order-processing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fdurable-functions-order-processing/lists"}