Uredi

Test locally by using the Azure Event Hubs emulator

The Azure Event Hubs emulator lets you test and validate your applications locally, without connecting to the cloud. This article shows you how to set up, run, and interact with the emulator by using Docker or an automated script.

Prerequisites

Note

Before you continue with the steps in this article, ensure Docker Desktop is running.

Run the Azure Event Hubs emulator

Run the Azure Event Hubs emulator by using either an automated script or a Linux container. Choose the method that best fits your development environment.

Before you run an automated script, clone the emulator's GitHub installer repository locally.

Windows

Use the following steps to run the Event Hubs emulator locally on Windows.

  1. Open PowerShell and go to the directory where you cloned the common scripts folder, by using cd.

    cd <path to your common scripts folder> # Update this path
    
  2. Enter the wsl command to open WSL in this directory.

    wsl
    
  3. Run the setup script LaunchEmulator.sh. The script brings up two containers: the Event Hubs emulator and Azurite, a dependency for the emulator.

    ./LaunchEmulator.sh
    

Linux and macOS

To run the Event Hubs emulator locally on Linux or macOS:

  • Run the setup script LaunchEmulator.sh. Running the script brings up two containers: the Event Hubs emulator and Azurite (a dependency for the emulator).

After the steps are successful, you can find the containers running in Docker.

Screenshot of the Azure Event Hubs emulator running in a container.

Interact with the emulator

By default, the emulator uses the config.json configuration file. You can configure entities, such as event hubs and Kafka topics, by editing this file. For more information, see Quota configuration changes.

The connection string that you use to connect to the Event Hubs emulator depends on where your application runs:

  • When the emulator container and your application run natively on the local machine, use this connection string:

    "Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"
    
  • When your application runs on a different machine on the same local network (containerized or not), connect to the emulator by using the IPv4 address of the host machine:

    "Endpoint=sb://192.168.y.z;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"
    
  • When your application container runs on the same bridge network, connect to the emulator by using its alias or IP address. This connection string assumes that the emulator uses the default name, eventhubs-emulator:

    "Endpoint=sb://eventhubs-emulator;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"
    
  • When your application container runs on a different bridge network, connect to the emulator by using host.docker.internal as the host:

    "Endpoint=sb://host.docker.internal;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"
    

To interact with Kafka, set the producer and consumer configuration as follows:

{
    BootstrapServers =  // The value depends on the connection string that you use.
    SecurityProtocol = SecurityProtocol.SaslPlaintext,
    SaslMechanism = SaslMechanism.Plain,
    SaslUsername = "$ConnectionString",
    SaslPassword =  // The value depends on your topology.
};

The values of BootstrapServers and SaslPassword depend on your setup topology. For details, see the Interact with the emulator section.

Important

When you use Kafka, only the producer and consumer APIs are compatible with the Event Hubs emulator.

To get started, see the Event Hubs emulator samples on GitHub.