Decouple backend processing from a frontend host, where backend processing needs to be asynchronous, but the frontend still needs a clear response.
For more information about this pattern, see Asynchronous Request-Reply pattern on the Azure Architecture Center.
-
Clone or download this repo.
-
Navigate to the
async-request-replyfolder.cd async-request-reply -
Create a resource group.
az group create --name rg-asyncrequestreply --location eastus
-
Deploy the template.
az deployment group create -g rg-asyncrequestreply -f deploy.bicep
-
Wait for the deployment to complete.
-
Navigate to the
async-request-reply/srcfolder.cd src -
Deploy the app.
FUNC_APP_NAME=$(az deployment group show -g rg-asyncrequestreply -n deploy --query properties.outputs.functionAppName.value -o tsv) func azure functionapp publish $FUNC_APP_NAME --dotnet
-
Send an http request through the Async Processor Work Acceptor
curl -X POST "https://${FUNC_APP_NAME}.azurewebsites.net/api/asyncprocessingworkacceptor" --header 'Content-Type: application/json' --header 'Accept: application/json' -k -i -d '{ "id": "1234", "customername": "Contoso" }'
The response will be something like:
HTTP/1.1 202 Accepted Content-Length: 155 Content-Type: application/json; charset=utf-8 Date: Wed, 13 Dec 2023 20:18:55 GMT Location: http://<appservice-name>.azurewebsites.net/api/RequestStatus/<guid>
Using a browser open the url from the Location field in the response. A file with the data you have sent will be downloaded.
Note the app uses the WEBSITE_HOSTNAME environment variable. This environment variable is set automatically by the Azure App Service runtime environment. For more information, see Azure runtime environment
-
Delete all the Azure resources for this Cloud Async Pattern
az group delete -n rg-asyncrequestreply -y
You could open the solution with Visual Studio, then you need to create on the root local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ServiceBusConnectionAppSetting": "<yourdata>",
"StorageConnectionAppSetting": "<yourData>"
}
}