Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions docs/azureai/azureai-openai-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire Azure AI OpenAI component
description: Learn how to use the .NET Aspire Azure AI OpenAI component.
ms.topic: how-to
ms.date: 03/13/2024
ms.date: 04/04/2024
---

# .NET Aspire Azure AI OpenAI component
Expand Down Expand Up @@ -54,7 +54,22 @@ public class ExampleService(OpenAIClient client)

## App host usage

[!INCLUDE [azure-component-nuget](../includes/azure-component-nuget.md)]
To add Azure AI hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CognitiveServices](https://www.nuget.org/packages/Aspire.Hosting.Azure.CognitiveServices) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Hosting.Azure.CognitiveServices --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices"
Version="[SelectVersion]" />
```

---

In your app host project, register an Azure AI OpenAI resource using the following methods, such as <xref:Aspire.Hosting.AzureResourceExtensions.AddAzureOpenAI%2A>:

Expand Down
19 changes: 17 additions & 2 deletions docs/azureai/azureai-search-document-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: NET Aspire Azure AI Search Documents component
description: Learn how to use the NET Aspire Azure AI Search Documents component.
ms.topic: how-to
ms.date: 03/11/2024
ms.date: 04/04/2024
---

# NET Aspire Azure AI Search Documents component
Expand Down Expand Up @@ -75,7 +75,22 @@ For more information, see the [Azure AI Search client library for .NET](https://

## App host usage

[!INCLUDE [azure-component-nuget](../includes/azure-component-nuget.md)]
To add Azure Cosmos DB hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CosmosDB](https://www.nuget.org/packages/Aspire.Hosting.Azure.CosmosDB) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Hosting.Azure.CosmosDB --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Hosting.Azure.CosmosDB"
Version="[SelectVersion]" />
```

---

In the _Program.cs_ file of `AppHost`, add an Azure Search service and consume the connection using the following methods:

Expand Down
19 changes: 17 additions & 2 deletions docs/database/azure-cosmos-db-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire Azure Cosmos DB component
description: This article describes the .NET Aspire Azure Cosmos DB component features and capabilities.
ms.topic: how-to
ms.date: 03/13/2024
ms.date: 04/04/2024
---

# .NET Aspire Azure Cosmos DB component
Expand Down Expand Up @@ -51,7 +51,22 @@ For more information on using the <xref:Microsoft.Azure.Cosmos.CosmosClient>, se

## App host usage

[!INCLUDE [azure-component-nuget](../includes/azure-component-nuget.md)]
To add Azure Cosmos DB hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CosmosDB](https://www.nuget.org/packages/Aspire.Hosting.Azure.CosmosDB) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Hosting.Azure.CosmosDB --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Hosting.Azure.CosmosDB"
Version="[SelectVersion]" />
```

---

In your app host project, register the .NET Aspire Azure Cosmos DB component and consume the service using the following methods:

Expand Down
19 changes: 17 additions & 2 deletions docs/database/azure-cosmos-db-entity-framework-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: .NET Aspire Microsoft Entity Framework Core Cosmos DB component
description: This article describes the .NET Aspire Microsoft Entity Framework Core Cosmos DB component features and capabilities.
ms.topic: how-to
ms.date: 01/22/2024
ms.date: 04/04/2024
---

# .NET Aspire Microsoft Entity Framework Core Cosmos DB component
Expand Down Expand Up @@ -51,7 +51,22 @@ For more information on using Entity Framework Core with Azure Cosmos DB, see th

## App host usage

[!INCLUDE [azure-component-nuget](../includes/azure-component-nuget.md)]
To add Azure Cosmos DB hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CosmosDB](https://www.nuget.org/packages/Aspire.Hosting.Azure.CosmosDB) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Hosting.Azure.CosmosDB --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Hosting.Azure.CosmosDB"
Version="[SelectVersion]" />
```

---

In your app host project, register the .NET Aspire Microsoft Entity Framework Core Cosmos DB component and consume the service using the following methods:

Expand Down
21 changes: 0 additions & 21 deletions docs/includes/azure-component-nuget.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ conceptualContent:
- itemType: tutorial
text: Implement Messaging with .NET Aspire
url: messaging/messaging-components.md
- itemType: overview
text: Azure Event Hubs
url: messaging/azure-event-hubs-component.md
- itemType: overview
text: Azure Service Bus
url: messaging/azure-service-bus-component.md
Expand Down
213 changes: 213 additions & 0 deletions docs/messaging/azure-event-hubs-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
title: .NET Aspire Azure Event Hubs component
description: This article describes the .NET Aspire Azure Event Hubs component features and capabilities.
ms.topic: how-to
ms.date: 04/04/2024
---

# .NET Aspire Azure Event Hubs component

In this article, you learn how to use the .NET Aspire Azure Event Hubs component. The `Aspire.Azure.Messaging.EventHubs` library offers options for registering an <xref:Azure.Messaging.EventHubs.Producer.EventHubProducerClient>, an <xref:Azure.Messaging.EventHubs.Consumer.EventHubConsumerClient>, an <xref:Azure.Messaging.EventHubs.EventProcessorClient> or a <xref:Azure.Messaging.EventHubs.Primitives.PartitionReceiver> in the DI container for connecting to [Azure Event Hubs](/azure/event-hubs).

## Prerequisites

- Azure subscription: [create one for free](https://azure.microsoft.com/free/).
- Azure Event Hubs namespace: for more information, see [add an Event Hubs namespace](/azure/event-hubs/event-hubs-create). Alternatively, you can use a connection string, which isn't recommended in production environments.

## Get started

To get started with the .NET Aspire Azure Event Hubs component, install the [Aspire.Azure.Messaging.EventHubs](https://www.nuget.org/packages/Aspire.Azure.Messaging.EventHubs) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Azure.Messaging.EventHubs --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Azure.Messaging.EventHubs"
Version="[SelectVersion]" />
```

---

For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-package) or [Manage package dependencies in .NET applications](/dotnet/core/tools/dependencies).

## 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` |
| `EventProcessorClient` | `EventProcessorClientOptions` | `AzureMessagingEventHubsProcessorSettings` |
| `PartitionReceiver` | `PartitionReceiverOptions` | `AzureMessagingEventHubsPartitionReceiverSettings` |

## Example usage

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 `PartitionReceiver`are configured in a similar manner.

In the _Program.cs_ file of your component-consuming project, call the `AddAzureEventHubProducerClient` extension to register a `EventHubProducerClient` for use via the dependency injection container.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the _Program.cs_ file of your component-consuming project, call the `AddAzureEventHubProducerClient` extension to register a `EventHubProducerClient` for use via the dependency injection container.
In the _Program.cs_ file of your component-consuming project, call the `AddAzureEventHubProducerClient` extension to register an `EventHubProducerClient` for use via the dependency injection container.


```csharp
builder.AddAzureEventHubProducerClient("eventHubsConnectionName");
```

You can then retrieve the `EventHubProducerClient` instance using dependency injection. For example, to retrieve the client from a service:

```csharp
public class ExampleService(EventHubProducerClient client)
{
// Use client...
}
```

For more information, see the [Azure.Messaging.EventHubs documentation](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventhub/Azure.Messaging.EventHubs/README.md) for examples on using the `EventHubProducerClient`.

## App host usage

To add Azure Event Hub hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.EventHubs](https://www.nuget.org/packages/Aspire.Hosting.Azure.EventHubs) NuGet package.

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Aspire.Hosting.Azure.EventHubs --prerelease
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Aspire.Hosting.Azure.EventHubs"
Version="[SelectVersion]" />
```

---

In your app host project, add an Event Hubs connection and an Event Hub resource and consume the connection using the following methods:

```csharp
var eventHubs = builder.AddAzureEventHubs("eventHubsConnectionName")
.AddEventHub("MyHub");;

var ExampleService = builder.AddProject<Projects.ExampleService>()
.WithReference(eventHubs);
```

The `AddAzureEventHubs` method will 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 `ExampleService` project.

> [!IMPORTANT]
> Even though we are creating an Event Hub using the `AddEventHub` at the same time as the namespace, as of .NET Aspire version `preview-5`, 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> Even though we are creating an Event Hub using the `AddEventHub` at the same time as the namespace, as of .NET Aspire version `preview-5`, 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.
> Even though we are creating an Event Hub using the `AddEventHub` method at the same time as the namespace, as of .NET Aspire version `preview-5`, 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 `ExampleService`, the connection can be consumed using by calling of the supported Event Hubs client extension methods:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the _Program.cs_ file of `ExampleService`, the connection can be consumed using by calling of the supported Event Hubs client extension methods:
In the _Program.cs_ file of `ExampleService`, the connection can be consumed by calling the supported Event Hubs client extension methods:


```csharp
builder.AddAzureEventProcessorClient(
"eventHubsConnectionName",
static settings =>
{
settings.EventHubName = "MyHub";
});
```

## 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. Either a `Namespace` 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:

```csharp
builder.AddAzureEventHubProducerClient(
"eventHubsConnectionName",
static settings =>
{
settings.EventHubName = "MyHub";
});
```

And then the connection information will be retrieved from the `ConnectionStrings` configuration section. Two connection formats are supported:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And then the connection information will be retrieved from the `ConnectionStrings` configuration section. Two connection formats are supported:
And then the connection information is retrieved from the `ConnectionStrings` configuration section. Two connection formats are supported:


#### Fully Qualified Namespace (FQN)

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](https://learn.microsoft.com/dotnet/api/azure.identity.defaultazurecredential) is used.

```json
{
"ConnectionStrings": {
"eventHubsConnectionName": "{your_namespace}.servicebus.windows.net"
}
}
```

#### Connection string

Alternatively, use a connection string:

```json
{
"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](https://learn.microsoft.com/dotnet/api/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. For example, consider the `appsettings.json` that configures some of the options for an `EventProcessorClient`:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The .NET Aspire Azure Event Hubs library supports [Microsoft.Extensions.Configuration](https://learn.microsoft.com/dotnet/api/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. For example, consider the `appsettings.json` that configures some of the options for an `EventProcessorClient`:
The .NET Aspire Azure Event Hubs library supports [Microsoft.Extensions.Configuration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration). It loads the `AzureMessagingEventHubsSettings` and the associated Options, such as `EventProcessorClientOptions`, from configuration by using the `Aspire:Azure:Messaging:EventHubs:` key prefix, followed by the name of the specific client in use. For example, consider the `appsettings.json` that configures some of the options for an `EventProcessorClient`:


```json
{
"Aspire": {
"Azure": {
"Messaging": {
"EventHubs": {
"EventProcessorClient": {
"EventHubName": "MyHub",
"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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
You can also set up the Options type by 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:


```csharp
builder.AddAzureEventProcessorClient(
"eventHubsConnectionName",
configureClientBuilder: clientBuilder => clientBuilder.ConfigureOptions(
options => options.Identifier = "PROCESSOR_ID"));
```

[!INCLUDE [component-observability-and-telemetry](../includes/component-observability-and-telemetry.md)]

### Logging

The .NET Aspire Azure Event Hubs component uses the following log categories:

- `Azure.Core`
- `Azure.Identity`

### Tracing

The .NET Aspire Azure Event Hubs component will emit the following tracing activities using OpenTelemetry:

- "Azure.Messaging.EventHubs.*"

### Metrics

The .NET Aspire Azure Event Hubs component currently doesn't support metrics by default due to limitations with the Azure SDK for .NET. If that changes in the future, this section will be updated to reflect those changes.

## See also

- [Azure Event Hubs](/azure/event-hubs/)
- [.NET Aspire components](../fundamentals/components-overview.md)
- [.NET Aspire GitHub repo](https://github.com/dotnet/aspire)
Loading