Skip to content
Docs Try Aspire

AzureEventHubsExtensions Methods

Class Methods 13 members
Provides extension methods for adding the Azure Event Hubs resources to the application model.
AddAzureEventHubs(IDistributedApplicationBuilder, string) Section titled AddAzureEventHubs(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureEventHubsResource>
Adds an Azure Event Hubs Namespace resource to the application model. This resource can be used to create Event Hub resources.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsResource> AddAzureEventHubs(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builder IDistributedApplicationBuilder The builder for the distributed application.
name string The name of the resource.
IResourceBuilder<AzureEventHubsResource> A reference to the ApplicationModel.IResourceBuilder`1.
By default references to the Azure AppEvent Hubs Namespace resource will be assigned the following roles: - EventHubsBuiltInRole.AzureEventHubsDataOwner These can be replaced by calling AzureEventHubsExtensions.WithRoleAssignments.
AddConsumerGroup(IResourceBuilder<AzureEventHubResource>, string, string?) Section titled AddConsumerGroup(IResourceBuilder<AzureEventHubResource>, string, string?) extension IResourceBuilder<AzureEventHubConsumerGroupResource>
Adds an Azure Event Hub Consumer Group resource to the application model.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubConsumerGroupResource> AddConsumerGroup(
this IResourceBuilder<AzureEventHubResource> builder,
string name,
string? groupName = null)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubResource> The Azure Event Hub resource builder.
name string The name of the Event Hub Consumer Group resource.
groupName string? optional The name of the Consumer Group. If not provided, this defaults to the same value as name.
IResourceBuilder<AzureEventHubConsumerGroupResource> A reference to the ApplicationModel.IResourceBuilder`1.
AddEventHub(IResourceBuilder<AzureEventHubsResource>, string) Section titled AddEventHub(IResourceBuilder<AzureEventHubsResource>, string) extension IResourceBuilder<AzureEventHubsResource>
Adds an Azure Event Hubs hub resource to the application model. This resource requires an AzureEventHubsResource to be added to the application model.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsResource> AddEventHub(
this IResourceBuilder<AzureEventHubsResource> builder,
string name)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsResource> The Azure Event Hubs resource builder.
name string The name of the Event Hub.
IResourceBuilder<AzureEventHubsResource> A reference to the ApplicationModel.IResourceBuilder`1.
AddHub(IResourceBuilder<AzureEventHubsResource>, string, string?) Section titled AddHub(IResourceBuilder<AzureEventHubsResource>, string, string?) extension IResourceBuilder<AzureEventHubResource>
Adds an Azure Event Hubs hub resource to the application model.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubResource> AddHub(
this IResourceBuilder<AzureEventHubsResource> builder,
string name,
string? hubName = null)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsResource> The Azure Event Hubs resource builder.
name string The name of the Event Hub resource.
hubName string? optional The name of the Event Hub. If not provided, this defaults to the same value as name.
IResourceBuilder<AzureEventHubResource> A reference to the ApplicationModel.IResourceBuilder`1.
RunAsEmulator(IResourceBuilder<AzureEventHubsResource>, Action<IResourceBuilder<AzureEventHubsEmulatorResource>>) Section titled RunAsEmulator(IResourceBuilder<AzureEventHubsResource>, Action<IResourceBuilder<AzureEventHubsEmulatorResource>>) extension IResourceBuilder<AzureEventHubsResource>
Configures an Azure Event Hubs resource to be emulated. This resource requires an AzureEventHubsResource to be added to the application model.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(
this IResourceBuilder<AzureEventHubsResource> builder,
Action<IResourceBuilder<AzureEventHubsEmulatorResource>>? configureContainer = null)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsResource> The Azure Event Hubs resource builder.
configureContainer Action<IResourceBuilder<AzureEventHubsEmulatorResource>> optional Callback that exposes underlying container used for emulation to allow for customization.
IResourceBuilder<AzureEventHubsResource> A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the / container image.

The following example creates an Azure Event Hubs resource that runs locally is an emulator and referencing that resource in a .NET project.

var builder = DistributedApplication.CreateBuilder(args);
var eventHub = builder.AddAzureEventHubs("eventhubns")
.RunAsEmulator()
.AddEventHub("hub");
builder.AddProject<Projects.InventoryService>()
.WithReference(eventHub);
builder.Build().Run();
WithConfiguration(IResourceBuilder<AzureEventHubsEmulatorResource>, Action<JsonNode>) Section titled WithConfiguration(IResourceBuilder<AzureEventHubsEmulatorResource>, Action<JsonNode>) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Alters the JSON configuration document used by the emulator.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithConfiguration(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
Action<JsonNode> configJson)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource.
configJson Action<JsonNode> A callback to update the JSON object representation of the configuration.
IResourceBuilder<AzureEventHubsEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1.
WithConfigurationFile(IResourceBuilder<AzureEventHubsEmulatorResource>, string) Section titled WithConfigurationFile(IResourceBuilder<AzureEventHubsEmulatorResource>, string) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Adds a bind mount for the configuration file of an Azure Event Hubs emulator resource.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithConfigurationFile(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
string path)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource.
path string Path to the file on the AppHost where the emulator configuration is located.
IResourceBuilder<AzureEventHubsEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1.
WithDataBindMount(IResourceBuilder<AzureEventHubsEmulatorResource>, string?) Section titled WithDataBindMount(IResourceBuilder<AzureEventHubsEmulatorResource>, string?) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Adds a bind mount for the data folder to an Azure Event Hubs emulator resource.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithDataBindMount(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
string? path = null)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource.
path string? optional Relative path to the AppHost where emulator storage is persisted between runs. Defaults to the path '.eventhubs/{builder.Resource.Name}'
IResourceBuilder<AzureEventHubsEmulatorResource> A builder for the AzureEventHubsEmulatorResource.
WithDataVolume(IResourceBuilder<AzureEventHubsEmulatorResource>, string?) Section titled WithDataVolume(IResourceBuilder<AzureEventHubsEmulatorResource>, string?) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Adds a named volume for the data folder to an Azure Event Hubs emulator resource.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithDataVolume(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
string? name = null)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource.
name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names.
IResourceBuilder<AzureEventHubsEmulatorResource> A builder for the AzureEventHubsEmulatorResource.
WithGatewayPort(IResourceBuilder<AzureEventHubsEmulatorResource>, int?) Section titled WithGatewayPort(IResourceBuilder<AzureEventHubsEmulatorResource>, int?) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Configures the host port for the Azure Event Hubs emulator is exposed on instead of using randomly assigned port.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithGatewayPort(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
int? port)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> Builder for the Azure Event Hubs emulator container
port int? The port to bind on the host. If null is used, a random port will be assigned.
IResourceBuilder<AzureEventHubsEmulatorResource> Azure Event Hubs emulator resource builder.
WithHostPort(IResourceBuilder<AzureEventHubsEmulatorResource>, int?) Section titled WithHostPort(IResourceBuilder<AzureEventHubsEmulatorResource>, int?) extension IResourceBuilder<AzureEventHubsEmulatorResource>
Configures the host port for the Azure Event Hubs emulator is exposed on instead of using randomly assigned port.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithHostPort(
this IResourceBuilder<AzureEventHubsEmulatorResource> builder,
int? port)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubsEmulatorResource> Builder for the Azure Event Hubs emulator container
port int? The port to bind on the host. If null is used, a random port will be assigned.
IResourceBuilder<AzureEventHubsEmulatorResource> Azure Event Hubs emulator resource builder.
WithProperties(IResourceBuilder<AzureEventHubResource>, Action<AzureEventHubResource>) Section titled WithProperties(IResourceBuilder<AzureEventHubResource>, Action<AzureEventHubResource>) extension IResourceBuilder<AzureEventHubResource>
Allows setting the properties of an Azure Event Hub resource.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<AzureEventHubResource> WithProperties(
this IResourceBuilder<AzureEventHubResource> builder,
Action<AzureEventHubResource> configure)
{
// ...
}
}
builder IResourceBuilder<AzureEventHubResource> The Azure Event Hub resource builder.
configure Action<AzureEventHubResource> A method that can be used for customizing the AzureEventHubResource.
IResourceBuilder<AzureEventHubResource> A reference to the ApplicationModel.IResourceBuilder`1.
WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureEventHubsResource>, EventHubsBuiltInRole[]) Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureEventHubsResource>, EventHubsBuiltInRole[]) extension IResourceBuilder<T>
Assigns the specified roles to the given resource, granting it the necessary permissions on the target Azure Event Hubs Namespace resource. This replaces the default role assignments for the resource.
public static class AzureEventHubsExtensions
{
public static IResourceBuilder<T> WithRoleAssignments<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<AzureEventHubsResource> target,
params EventHubsBuiltInRole[] roles)
{
// ...
}
}
builder IResourceBuilder<T> The resource to which the specified roles will be assigned.
target IResourceBuilder<AzureEventHubsResource> The target Azure Event Hubs Namespace resource.
roles EventHubsBuiltInRole[] The built-in Event Hubs roles to be assigned.
IResourceBuilder<T> The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.

Assigns the AzureEventHubsDataSender role to the 'Projects.Api' project.

var builder = DistributedApplication.CreateBuilder(args);
var eventHubs = builder.AddAzureEventHubs("eventHubs");
var api = builder.AddProject<Projects.Api>("api")
.WithRoleAssignments(eventHubs, EventHubsBuiltInRole.AzureEventHubsDataSender)
.WithReference(eventHubs);