Skip to content

Latest commit



88 lines (62 loc) · 3.78 KB

File metadata and controls

88 lines (62 loc) · 3.78 KB

Azure Functions, Event Hubs and Kafka Demo

Functions, Event Hubs and Kafka

This code in this repository demonstrates how to:

Accompanying blog post:

Setup with the Azure CLI:

The following steps will create an instance of Azure Event Hubs that is enabled with the Kafka protocol. It will also create an event hub (kafka topic) and an access policy for sending and listening to events. These steps can be achieved with the Azure Cloud Shell.

Initialize some variables:

rgname={your resource group name}
location={preferred azure region}
ehnamespace={unique event hubs namespace name}
ehname={event hub/topic name}

Create resources:

# create resource group
az group create -n $rgname -l $location

# create event hubs namespace with kafka enabled
az eventhubs namespace create -g $rgname --name $ehnamespace -l $location --sku Standard --enable-kafka true

# create event hub
az eventhubs eventhub create -g $rgname --namespace-name $ehnamespace --name $ehname

# create shared access policy with send and listen rights
az eventhubs eventhub authorization-rule create --eventhub-name $ehname --name $authorizationrule --namespace-name $ehnamespace -g $rgname --rights Send Listen

# query for the primary connection string
az eventhubs eventhub authorization-rule keys list --resource-group $rgname --namespace-name $ehnamespace --eventhub-name $ehname --name $authorizationrule --query "primaryConnectionString"

Azure Function as a Kafa Producer

This repository contains a HTTP-triggered function that takes the incoming request and passes it along to a kafka topic. The function also showcases how to leverage the recently released dependency injection support of .NET functions.

Function settings for local.settings.json:

    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "IsLocal": "1",
        "EventHubConnectionString": "{your-event-hub-connection-string}",
        "EventHubFqdn": "{event-hub-namespace}",
        "EventHubName": "{event-hub-name}"

Running in Azure

When deployed in Azure, the last three settings (EventHubConnectionString, EventHubFqdn, EventHubName) must be configured in the application settings.

The IsLocal setting should be emitted or set to "0".

Consume events with kafkacat

kafkacat is an easy-to-use utility for consuming events from a Kafka topic.


Install kafkacat: If you are using a Windows machine, you can use the Windows Subsystem for Linux (WSL).

Consume events

From the terminal:

# initialize variables
connectionString="{your event hub connection string}"
kafkaEndpoint="{event hub namespace name}"

# consume events (starting at the end offset)
kafkacat -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN -X sasl.username="\$ConnectionString" -X sasl.password=$connectionString -b $kafkaEndpoint -t $topicname -o end