Aspire.Azure.Messaging.EventHubs
13.0.1
Prefix Reserved
See the version list below for details.
dotnet add package Aspire.Azure.Messaging.EventHubs --version 13.0.1
NuGet\Install-Package Aspire.Azure.Messaging.EventHubs -Version 13.0.1
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" Version="13.0.1" />
<PackageVersion Include="Aspire.Azure.Messaging.EventHubs" Version="13.0.1" />
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" />
paket add Aspire.Azure.Messaging.EventHubs --version 13.0.1
#r "nuget: Aspire.Azure.Messaging.EventHubs, 13.0.1"
#:package Aspire.Azure.Messaging.EventHubs@13.0.1
#addin nuget:?package=Aspire.Azure.Messaging.EventHubs&version=13.0.1
#tool nuget:?package=Aspire.Azure.Messaging.EventHubs&version=13.0.1
Aspire.Azure.Messaging.EventHubs
Offers options for registering an EventHubProducerClient, an EventHubConsumerClient, an EventHubBufferedProducerClient, an EventProcessorClient or a PartitionReceiver in the DI container for connecting to Azure Event Hubs.
Getting started
Prerequisites
- Azure subscription - create one for free
- Azure Event Hubs namespace, learn more about how to add an Event Hubs namespace. Alternatively, you can use a connection string, which is not recommended in production environments.
Install the package
Install the .NET Aspire Azure Event Hubs library with NuGet:
dotnet add package Aspire.Azure.Messaging.EventHubs
Supported clients with Options classes
The following clients are supported by the library, along with their corresponding Options and Settings classes:
| Client Type | Options Class | Settings Class |
|---|---|---|
| EventHubProducerClient | EventHubProducerClientOptions | AzureMessagingEventHubsProducerSettings |
| EventHubConsumerClient | EventHubConsumerClientOptions | AzureMessagingEventHubsConsumerSettings |
| EventHubBufferedProducerClient | EventHubBufferedProducerClientOptions | AzureMessagingEventHubsBufferedProducerSettings |
| EventProcessorClient | EventProcessorClientOptions | AzureMessagingEventHubsProcessorSettings |
| PartitionReceiver | PartitionReceiverOptions | AzureMessagingEventHubsPartitionReceiverSettings |
Usage example
The following example assumes that you have an Azure Event Hubs namespace and an Event Hub created and wish to configure an EventHubProducerClient to send events to the Event Hub. The EventHubConsumerClient, EventProcessorClient, and PartitionReceiverare configured in a similar manner.
In the AppHost.cs file of your project, call the AddAzureEventHubProducerClient extension method to register
a EventHubProducerClient for use via the dependency injection container. The method takes a connection name parameter. This assumes you have included the EntityPath in the connection string to specify the Event Hub name.
builder.AddAzureEventHubProducerClient("eventHubsConnectionName");
Retrieve the EventHubProducerClient instance using dependency injection. For example, to retrieve the
client from a Web API controller:
private readonly EventHubProducerClient _client;
public ProductsController(EventHubProducerClient client)
{
_client = client;
}
See the Azure.Messaging.EventHubs documentation for examples on using the EventHubProducerClient.
Configuration
The .NET Aspire Azure Event Hubs library provides multiple options to configure the Azure Event Hubs connection based on the requirements and conventions of your project. Note that either a FullyQualifiedNamespace or a ConnectionString is a required to be supplied.
Use a connection string
When using a connection string from the ConnectionStrings configuration section, provide the name of the connection string when calling builder.AddAzureEventHubProducerClient() and other supported Event Hubs clients. In this example, the connection string does not include the EntityPath property, so the EventHubName property must be set in the settings callback:
builder.AddAzureEventHubProducerClient("eventHubsConnectionName",
settings =>
{
settings.EventHubName = "MyHub";
});
And then the connection information will be retrieved from the ConnectionStrings configuration section. Two connection formats are supported:
Fully Qualified Namespace
The recommended approach is to use a fully qualified namespace, which works with the AzureMessagingEventHubsSettings.Credential property to establish a connection. If no credential is configured, the DefaultAzureCredential is used.
{
"ConnectionStrings": {
"eventHubsConnectionName": "{your_namespace}.servicebus.windows.net"
}
}
Connection string
Alternatively, use a connection string:
{
"ConnectionStrings": {
"eventHubsConnectionName": "Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=accesskeyname;SharedAccessKey=accesskey;EntityPath=MyHub"
}
}
Use configuration providers
The .NET Aspire Azure Event Hubs library supports Microsoft.Extensions.Configuration. It loads the AzureMessagingEventHubsSettings and the associated Options, e.g. EventProcessorClientOptions, from configuration by using the Aspire:Azure:Messaging:EventHubs: key prefix, followed by the name of the specific client in use. Example appsettings.json that configures some of the options for an EventProcessorClient:
{
"Aspire": {
"Azure": {
"Messaging": {
"EventHubs": {
"EventProcessorClient": {
"EventHubName": "MyHub",
"BlobContainerName": "checkpoints",
"ClientOptions": {
"Identifier": "PROCESSOR_ID"
}
}
}
}
}
}
}
You can also setup the Options type using the optional Action<IAzureClientBuilder<EventProcessorClient, EventProcessorClientOptions>> configureClientBuilder parameter of the AddAzureEventProcessorClient method. For example, to set the processor's client ID for this client:
builder.AddAzureEventProcessorClient("eventHubsConnectionName",
configureClientBuilder: clientBuilder => clientBuilder.ConfigureOptions(
options => options.Identifier = "PROCESSOR_ID"));
AppHost extensions
In your AppHost project, install the Aspire Azure Event Hubs Hosting library with NuGet:
dotnet add package Aspire.Hosting.Azure.EventHubs
Then, in the AppHost.cs file of AppHost, add an Event Hubs connection and an Event Hub resource and consume the connection using the following methods:
var eventHubs = builder.ExecutionContext.IsPublishMode
? builder.AddAzureEventHubs("eventHubsConnectionName").WithHub("MyHub")
: builder.AddConnectionString("eventHubsConnectionName");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(eventHubs);
The AddAzureEventHubs method adds an Azure Event Hubs Namespace resource to the builder. Or AddConnectionString can be used to read connection information from the AppHost's configuration (for example, from "user secrets") under the ConnectionStrings:eventHubsConnectionName config key. The WithReference method passes that connection information into a connection string named eventHubsConnectionName in the MyService project.
NOTE: Even though we are creating an Event Hub using the WithHub at the same time as the namespace, for this release of Aspire, the connection string will not include the EntityPath property, so the EventHubName property must be set in the settings callback for the preferred client. Future versions of Aspire will include the EntityPath property in the connection string and will not require the EventHubName property to be set in this scenario.
In the Program.cs file of MyService, the connection can be consumed using by calling of the supported Event Hubs client extension methods:
builder.AddAzureEventProcessorClient("eventHubsConnectionName", settings =>
{
settings.EventHubName = "MyHub";
});
Additional documentation
- https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Microsoft.Azure.EventHubs/README.md
- https://github.com/dotnet/aspire/tree/main/src/Components/README.md
Feedback & contributing
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- AspNetCore.HealthChecks.Azure.Messaging.EventHubs (>= 9.0.0)
- Azure.Core (>= 1.49.0)
- Azure.Identity (>= 1.17.0)
- Azure.Messaging.EventHubs (>= 5.12.2)
- Azure.Messaging.EventHubs.Processor (>= 5.12.2)
- Azure.Storage.Blobs (>= 12.26.0)
- Microsoft.Extensions.Azure (>= 1.13.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Primitives (>= 10.0.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- System.IO.Hashing (>= 9.0.10)
-
net8.0
- AspNetCore.HealthChecks.Azure.Messaging.EventHubs (>= 9.0.0)
- Azure.Core (>= 1.49.0)
- Azure.Identity (>= 1.17.0)
- Azure.Messaging.EventHubs (>= 5.12.2)
- Azure.Messaging.EventHubs.Processor (>= 5.12.2)
- Azure.Storage.Blobs (>= 12.26.0)
- Microsoft.Extensions.Azure (>= 1.13.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.22)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- System.IO.Hashing (>= 9.0.10)
-
net9.0
- AspNetCore.HealthChecks.Azure.Messaging.EventHubs (>= 9.0.0)
- Azure.Core (>= 1.49.0)
- Azure.Identity (>= 1.17.0)
- Azure.Messaging.EventHubs (>= 5.12.2)
- Azure.Messaging.EventHubs.Processor (>= 5.12.2)
- Azure.Storage.Blobs (>= 12.26.0)
- Microsoft.Extensions.Azure (>= 1.13.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Options (>= 9.0.11)
- Microsoft.Extensions.Primitives (>= 9.0.11)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- System.IO.Hashing (>= 9.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 13.0.2 | 0 | 12/4/2025 | |
| 13.0.1 | 1,338 | 11/26/2025 | |
| 13.0.0 | 4,500 | 11/11/2025 | |
| 9.5.2 | 24,324 | 10/23/2025 | |
| 9.5.1 | 17,486 | 10/3/2025 | |
| 9.5.0 | 3,923 | 9/25/2025 | |
| 9.4.2 | 9,825 | 9/2/2025 | |
| 9.4.1 | 23,571 | 8/12/2025 | |
| 9.4.0 | 5,436 | 7/29/2025 | |
| 9.3.1 | 39,471 | 6/10/2025 | |
| 9.3.0 | 4,926 | 5/19/2025 | |
| 9.2.1 | 5,922 | 4/24/2025 | |
| 9.2.0 | 2,412 | 4/10/2025 | |
| 9.1.0 | 22,434 | 2/25/2025 | |
| 9.0.0 | 34,129 | 11/12/2024 | |
| 9.0.0-rc.1.24511.1 | 532 | 10/15/2024 | |
| 8.2.2 | 3,578 | 10/24/2024 | |
| 8.2.1 | 11,212 | 9/26/2024 | |
| 8.2.0 | 2,957 | 8/29/2024 | |
| 8.1.0-preview.1.24373.2 | 1,868 | 7/23/2024 | |
| 8.0.2-preview.1.24326.4 | 284 | 6/28/2024 | |
| 8.0.1-preview.8.24267.1 | 552 | 5/21/2024 | |
| 8.0.0-preview.8.24258.2 | 214 | 5/21/2024 | |
| 8.0.0-preview.7.24251.11 | 280 | 5/7/2024 | |
| 8.0.0-preview.6.24214.1 | 248 | 4/23/2024 | |
| 8.0.0-preview.5.24201.12 | 228 | 4/9/2024 |