Azure Event Hubs libraries for .NET

Overview

Azure Event Hubs is a highly scalable data streaming platform and event ingestion service.

To learn more about Azure Event Hubs, read the article What is Event Hubs?. To get started, check out the Event Hubs Programming Guide.

Client library

Use the Event Hubs client to send and receive messages to and from Event Hubs.

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

Install-Package Microsoft.Azure.EventHubs
dotnet add package Microsoft.Azure.EventHubs

Code Example

The following code creates an Event Hubs client and sends a message to the hub.

EventHubsConnectionStringBuilder connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
{
    EntityPath = eventHubEntityPath
};

EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
string message = $"Message {i}";
Console.WriteLine($"Sending message: {message}");
await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));

Management library

Use the Event Hubs management library to create, update, and remove hubs and consumer groups.

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

Install-Package Microsoft.Azure.Management.EventHub
dotnet add package Microsoft.Azure.Management.EventHub

Code Example

The following code creates a new event hub.

TokenCredentials creds = new TokenCredentials(token);
EventHubManagementClient ehClient = new EventHubManagementClient(creds)
{
    SubscriptionId = subscriptionId
};

EventHubCreateOrUpdateParameters ehParams = new EventHubCreateOrUpdateParameters()
{
    Location = location
};

Console.WriteLine("Creating Event Hub...");
await ehClient.EventHubs.CreateOrUpdateAsync(resourceGroupName, namespaceName, EventHubName, ehParams);
Console.WriteLine("Created Event Hub successfully.");

Tutorials

Samples

Explore more sample .NET code you can use in your apps.