This folder contains the Python code for the Orchestrator Function. The Orchestrator Function manages the flow of the Saga, coordinating multiple steps and triggering compensating actions if needed.
orchestrator_function.py: Python code for the Orchestrator Function.requirements.txt: Lists the dependencies required by the Orchestrator Function.deploy-orchestrator.yml: GitHub Action workflow to automate the deployment of the Orchestrator Function.
- Azure Subscription: You need an active Azure account.
- Azure Function App: Ensure the Azure Function App is created (using the Bicep template in the
/infrastructurefolder). - GitHub Secrets Configuration:
AZURE_CREDENTIALS: Azure service principal credentials in JSON format.AZURE_FUNCTIONAPP_PUBLISH_PROFILE: Publish profile for the Azure Function App.ServiceBusConnection: Connection string for the Azure Service Bus namespace.CosmosDBConnectionString: Connection string for the Azure Cosmos DB account.
- Add Required Secrets to GitHub:
- Go to your repository's Settings > Secrets and variables > Actions > New repository secret.
- Add the following secrets:
AZURE_CREDENTIALS: Your Azure service principal credentials.AZURE_FUNCTIONAPP_PUBLISH_PROFILE: The publish profile for your Azure Function App.ServiceBusConnection: The connection string for your Azure Service Bus namespace.CosmosDBConnectionString: The connection string for your Azure Cosmos DB account.
Ensure the following environment variables are set in your Azure Function App configuration:
ServiceBusConnection: Connection string for the Azure Service Bus namespace.CosmosDBConnectionString: Connection string for the Azure Cosmos DB account.ActivityFunctionUrl: URL of the deployed Activity Function endpoint.
-
Run the GitHub Action:
- Push your changes to the
mainbranch or manually trigger the Deploy Orchestrator Function workflow from the Actions tab.
- Push your changes to the
-
Monitor the Deployment:
- Go to the Actions tab in your GitHub repository.
- Select the Deploy Orchestrator Function workflow to monitor the deployment progress.
-
Trigger the Orchestrator Function:
- The Orchestrator Function is triggered via an HTTP POST request to the
/startSagaendpoint. - Use an HTTP client (such as Postman or
curl) to send a request:
curl -X POST https://<your-orchestrator-function-app-name>.azurewebsites.net/api/startSaga \ -H "Content-Type: application/json" \ -d '{ "orderId": "12345", "customerName": "John Doe", "items": ["Laptop", "Smartphone"] }'
Replace
<your-orchestrator-function-app-name>with the name of your deployed Azure Function App. - The Orchestrator Function is triggered via an HTTP POST request to the
-
What Happens Next:
- The Orchestrator Function processes the request and calls the Activity Function to perform the transaction.
- If the transaction is successful, a success response is returned.
- If the transaction fails, the Compensator Function is triggered to revert or compensate for the failed transaction.
This project is licensed under the MIT License - see the LICENSE file for details.