This is a sample for writing durable functions with docker support enabled.
Requirements:
- .Net Core (>= 2.1.104)
- Azure CLI (>= 2.0.32)
- Azure Functions Core Tools (>= 2.0)
- Azure Storage Emulator (>= 5.3)
- httpie (>= 0.9.8)
- docker (>= 17.12.0-ce)
Github Deployment Sync Enabled.
$Subscription = "<your_subscription>"
$Prefix = "<unique_prefix>"
.\install.ps1 -Prefix $Prefix -Subscription $Subscription
git clone https://github.com/danielscholl/azure-functions-durable.git azure-functions-durable
# Initialize a new Function App
func init --worker-runtime dotnet
# Create a dotnet project
dotnet new lib --name azure-functions-durable -o .
rm Class1.cs
# Add Library Dependencies
dotnet add package Microsoft.AspNetCore.Http -v 2.1.0-rc1-final
dotnet add package Microsoft.AspNetCore.Mvc -v 2.1.0-rc1-final
dotnet add package Microsoft.AspNetCore.Mvc.WebApiCompatShim -v 2.1.0-rc1-final
dotnet add package Microsoft.Azure.WebJobs -v 3.0.0-beta5
dotnet add package Microsoft.Azure.WebJobs.Extensions.DurableTask -v 1.4.1
dotnet add package Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator -v 1.0.0-beta3
- Option 1: Use Azure Storage Emulator
AzureStorageEmulator.exe start
- Option 1: Use Azure Storage Account
For this section shell out to bash (ubuntu)
# Login to Azure and set subscription if necessary
Subscription='<azure_subscription_name>'
az login
az account set --subscription ${Subscription}
# Create Resource Group
ResourceGroup="durablefunctions"
Location="southcentralus"
az group create --name ${ResourceGroup} \
--location ${Location} \
-ojsonc
# Create a Storage Account
StorageAccount="durablefunctions"$(date "+%m%d%Y")
if $(az storage account check-name --name ${StorageAccount} --query nameAvailable -otsv); then
az storage account create --name ${StorageAccount} \
--resource-group ${ResourceGroup} \
--location ${Location} \
--sku "Standard_LRS" \
-ojsonc
fi
# Set Storage Account Context
export STORAGE_CONNECTION=$(az storage account show-connection-string \
--name ${StorageAccount} \
--resource-group ${ResourceGroup} \
--query connectionString -otsv)
# Set Storage Account into .envrc file
echo "export STORAGE_ACCOUNT='${STORAGE_CONNECTION}'" > .envrc
# Create local.settings.json file
cat > local.settings.json << EOF1
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "${STORAGE_CONNECTION}",
"AzureWebJobsDashboard": "${STORAGE_CONNECTION}"
}
}
EOF1
-
Create It
func new -l C# -t "Http Trigger" -n ping
-
Edit It
Modify the ping/run.csx file to be a simple pong return
using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; public static IActionResult Run(HttpRequest req, TraceWriter log) { log.Info("Ping Test Executed."); return (ActionResult)new OkObjectResult($"Pong"); }
-
Test It Locally
# Start It func start # Trigger It http post http://localhost:7071/api/ping # Result HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Date: Fri, 01 Jun 2018 16:44:01 GMT Server: Kestrel Transfer-Encoding: chunked Pong # Log Analytics Query // Ping AIQL Logging Query traces | where operation_Name == "ping" | where customDimensions.Category == "Function.ping.User" | where severityLevel == 1 | where timestamp > ago(10m) | sort by timestamp asc | project timestamp, operation_Id, operation_Name, severityLevel , message
-
Test It Remotely
For this section shell out to bash (ubuntu)
# Retrive Information
RESOURCE_GROUP="durablefunctions"
NAME=$(az functionapp list \
--resource-group ${RESOURCE_GROUP} \
--query [].name -otsv)
WEBHOST="https://"$(az functionapp list \
--resource-group ${RESOURCE_GROUP} \
--query [].defaultHostName -otsv)
# Connect to Log Stream
az webapp log tail \
--resource-group ${RESOURCE_GROUP} \
--name ${NAME}
# Trigger it
http get $WEBHOST/api/ping
az webapp log tail --resource-group durablefunctions --name dks5qmjppnvdlaqg-func