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) { // ... }}Parameters
builder IDistributedApplicationBuilder The builder for the distributed application. name string The name of the resource. Returns
IResourceBuilder<AzureEventHubsResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
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) { // ... }}Parameters
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. Returns
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) { // ... }}Parameters
builder IResourceBuilder<AzureEventHubsResource> The Azure Event Hubs resource builder. name string The name of the Event Hub. Returns
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) { // ... }}Parameters
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. Returns
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) { // ... }}Parameters
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. Returns
IResourceBuilder<AzureEventHubsResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
This version of the package defaults to the tag of the / container image.
Examples
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) { // ... }}Parameters
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource. configJson Action<JsonNode> A callback to update the JSON object representation of the configuration. Returns
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) { // ... }}Parameters
builder IResourceBuilder<AzureEventHubsEmulatorResource> The builder for the AzureEventHubsEmulatorResource. path string Path to the file on the AppHost where the emulator configuration is located. Returns
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) { // ... }}Parameters
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}' Returns
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) { // ... }}Parameters
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. Returns
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) { // ... }}Parameters
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. Returns
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) { // ... }}Parameters
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. Returns
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) { // ... }}Parameters
builder IResourceBuilder<AzureEventHubResource> The Azure Event Hub resource builder. configure Action<AzureEventHubResource> A method that can be used for customizing the AzureEventHubResource. Returns
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) { // ... }}Parameters
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. Returns
IResourceBuilder<T> The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments. Examples
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);