-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Figure out how to process event hub messages using an Azure Functions custom handler #90
Comments
I need to install the azure-functions-core-tools: $ brew search azure-functions-core-tools
==> Formulae
azure/functions/azure-functions-core-tools azure/functions/azure-functions-core-tools@2 azure/functions/azure-functions-core-tools@4 ✔
azure/functions/azure-functions-core-tools-v3-preview azure/functions/azure-functions-core-tools@3 I already have Update the local install to the latest version available: $ brew upgrade azure/functions/azure-functions-core-tools@4 |
Create a new Function App with a custom worker runtime: $ func init azure-streamer --worker-runtime custom
Writing .gitignore
Writing host.json
Writing local.settings.json
Writing /Users/zmoog/code/projects/zmoog/azure-streamer/.vscode/extensions.json |
Now, we have a Function App, so it's time to create a function. Listing the function templates: $ func templates list
C# Templates:
<redacted>
Custom Templates:
Azure Blob Storage trigger
Azure Cosmos DB trigger
Azure Event Grid trigger
Azure Event Hub trigger
HTTP trigger
IoT Hub (Event Hub)
Kafka trigger
Azure Queue Storage trigger
RabbitMQ trigger
SendGrid
Azure Service Bus Queue trigger
Azure Service Bus Topic trigger
SignalR negotiate HTTP trigger
Timer trigger
JavaScript Templates:
<redacted>
PowerShell Templates:
<redacted>
Python Templates:
<redacted>
TypeScript Templates:
<redacted> Creating a new function using the "Azure Event Hub trigger" template: $ func new --name receive --template "Azure Event Hub trigger"
Select a number for template:Azure Event Hub trigger
Function name: [EventHubTrigger] Writing /Users/zmoog/code/projects/zmoog/azure-streamer/receive/function.json
The function "receive" was created successfully from the "Azure Event Hub trigger" template.
$ tree .
.
├── host.json
├── local.settings.json
└── receive
└── function.json
1 directory, 3 files
$ cat receive/function.json
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "eventHubMessages",
"direction": "in",
"eventHubName": "samples-workitems",
"connection": "",
"cardinality": "many",
"consumerGroup": "$Default"
}
]
} |
Now it's time to create a few resources in Azure. Set environment variablesAs suggested by the tutorial, I will use the following environment variables in all commands: export RESOURCE_GROUP=mbranca-azure-streamer
export EVENT_HUB_NAMESPACE=mbrancaazurestreamer
export EVENT_HUB_NAME=activitylogs
export EVENT_HUB_AUTHORIZATION_RULE=ListenOnly
export STORAGE_ACCOUNT=mbrancaazurestreamer
export FUNCTION_APP=mbranca-azure-streamer
export LOCATION=eastus2 Create a resource groupaz group create \
--name $RESOURCE_GROUP \
--location $LOCATION Create an event hubaz eventhubs namespace create \
--resource-group $RESOURCE_GROUP \
--sku Basic \
--name $EVENT_HUB_NAMESPACE
az eventhubs eventhub create \
--resource-group $RESOURCE_GROUP \
--name $EVENT_HUB_NAME \
--namespace-name $EVENT_HUB_NAMESPACE \
--retention-time-in-hours 24 \
--cleanup-policy delete
az eventhubs eventhub authorization-rule create \
--resource-group $RESOURCE_GROUP \
--name $EVENT_HUB_AUTHORIZATION_RULE \
--eventhub-name $EVENT_HUB_NAME \
--namespace-name $EVENT_HUB_NAMESPACE \
--rights Listen Create a storage account and function appaz storage account create \
--resource-group $RESOURCE_GROUP \
--name $STORAGE_ACCOUNT \
--sku Standard_LRS az functionapp create \
--resource-group $RESOURCE_GROUP \
--name $FUNCTION_APP \
--storage-account $STORAGE_ACCOUNT \
--consumption-plan-location $LOCATION \
--os-type linux \
--runtime custom \
--functions-version 4 Note that:
The function app seems a sort of container that can host multiple functions. |
Configure your function appRetrieve resource connection stringsAZURE_WEB_JOBS_STORAGE=$( \
az storage account show-connection-string \
--name $STORAGE_ACCOUNT \
--query connectionString \
--output tsv)
echo $AZURE_WEB_JOBS_STORAGE
EVENT_HUB_CONNECTION_STRING=$( \
az eventhubs eventhub authorization-rule keys list \
--resource-group $RESOURCE_GROUP \
--name $EVENT_HUB_AUTHORIZATION_RULE \
--eventhub-name $EVENT_HUB_NAME \
--namespace-name $EVENT_HUB_NAMESPACE \
--query primaryConnectionString \
--output tsv)
echo $EVENT_HUB_CONNECTION_STRING Update your function app settings
Check the settings values with: az functionapp config appsettings list --resource-group $RESOURCE_GROUP --name $FUNCTION_APP |
Requirements
brew upgrade azure/functions/azure-functions-core-tools@4
Refs
The text was updated successfully, but these errors were encountered: