Tech Talk

Load Testing Applications Consuming Azure Event Hub with k6

Load Testing Applications Consuming Azure Event Hub with k6
  • Yannick Rödl

  • 6 min

  • July 14, 2023

No official k6 extension for Azure Event Hub? No problem. Use the Apache Kafka adapter to push messages and run realistic load tests – with actual JSON files as payloads.

Send 29,000 Messages to Azure Event Hub in 2 Minutes With k6

k6 is a Go-based load testing framework with a JavaScript interface. We use it to test components consuming Azure Event Hub via the Apache Kafka interface.

Prerequisites

  1. Install k6
  2. Install Go
  3. Install xk6: go install go.k6.io/xk6/cmd/xk6@latest
  4. Build the Kafka extension: xk6 build --with github.com/mostafa/xk6-kafka@latest

This creates a new k6 executable. Use this custom binary – not the default k6 – for your tests.

Connecting to Azure Event Hub

Configure SASL and TLS for the Kafka interface:

  • Username: $ConnectionString                                                    
  • Password: the full connection string                                                      
  • Algorithm: SASL_PLAIN, TLS: TLS_1_2

Extract the broker URL and topic from environment variables passed via -e to k6.

Sending Messages

Use writer.produce({ messages }) inside the exported default function. To send multiple JSON files as payloads, load them with open() and iterate over fileContents.

Results

In a 2-minute test run, we ingested 29,140 messages into Azure Event Hub. For full performance monitoring, combine with Prometheus metrics on the consuming application.