Skip to content
DocsTry Aspire
DocsTry

AzureEventHubsExtensions Methods

ClassMethods13 members
Provides extension methods for adding the Azure Event Hubs resources to the application model.
AddAzureEventHubs(IDistributedApplicationBuilder, string)Section titled AddAzureEventHubs(IDistributedApplicationBuilder, string)extensionIResourceBuilder<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)
{
// ...
}
}
builderIDistributedApplicationBuilderThe builder for the distributed application.
namestringThe 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubResource>The Azure Event Hub resource builder.
namestringThe name of the Event Hub Consumer Group resource.
groupNamestring?optionalThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsResource>The Azure Event Hubs resource builder.
namestringThe 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsResource>The Azure Event Hubs resource builder.
namestringThe name of the Event Hub resource.
hubNamestring?optionalThe 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>>)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsResource>The Azure Event Hubs resource builder.
configureContainerAction<IResourceBuilder<AzureEventHubsEmulatorResource>>optionalCallback 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>)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>The builder for the AzureEventHubsEmulatorResource.
configJsonAction<JsonNode>A callback to update the JSON object representation of the configuration.
IResourceBuilder<AzureEventHubsEmulatorResource>A reference to the ApplicationModel.IResourceBuilder`1.
This method is not available in polyglot app hosts. Use AzureEventHubsExtensions.WithConfigurationFile instead.
WithConfigurationFile(IResourceBuilder<AzureEventHubsEmulatorResource>, string)Section titled WithConfigurationFile(IResourceBuilder<AzureEventHubsEmulatorResource>, string)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>The builder for the AzureEventHubsEmulatorResource.
pathstringPath 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>The builder for the AzureEventHubsEmulatorResource.
pathstring?optionalRelative 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>The builder for the AzureEventHubsEmulatorResource.
namestring?optionalThe 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>Builder for the Azure Event Hubs emulator container
portint?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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubsEmulatorResource>Builder for the Azure Event Hubs emulator container
portint?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>)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<AzureEventHubResource>The Azure Event Hub resource builder.
configureAction<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[])extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<T>The resource to which the specified roles will be assigned.
targetIResourceBuilder<AzureEventHubsResource>The target Azure Event Hubs Namespace resource.
rolesEventHubsBuiltInRole[]The built-in Event Hubs roles to be assigned.
IResourceBuilder<T>The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.
This overload is not available in polyglot app hosts. Use AzureEventHubsExtensions.WithRoleAssignments instead.

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);