AzureServiceBusExtensions Methods
Class Methods 16 members
Provides extension methods for adding the Azure Service Bus resources to the application model.
AddAzureServiceBus(IDistributedApplicationBuilder, string) Section titled AddAzureServiceBus(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureServiceBusResource> Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> AddAzureServiceBus( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builder IDistributedApplicationBuilder The builder for the distributed application. name string The name of the resource. Returns
IResourceBuilder<AzureServiceBusResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
By default references to the Azure Service Bus resource will be assigned the following roles: -
ServiceBusBuiltInRole.AzureServiceBusDataOwner These can be replaced by calling AzureServiceBusExtensions.WithRoleAssignments. AddQueue(IResourceBuilder<AzureServiceBusResource>, string) Section titled AddQueue(IResourceBuilder<AzureServiceBusResource>, string) extension IResourceBuilder<AzureServiceBusResource> Adds an Azure Service Bus Queue resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> AddQueue( this IResourceBuilder<AzureServiceBusResource> builder, string name) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. name string The name of the queue resource. Returns
IResourceBuilder<AzureServiceBusResource> A reference to the ApplicationModel.IResourceBuilder`1. AddServiceBusQueue(IResourceBuilder<AzureServiceBusResource>, string, string?) Section titled AddServiceBusQueue(IResourceBuilder<AzureServiceBusResource>, string, string?) extension IResourceBuilder<AzureServiceBusQueueResource> Adds an Azure Service Bus Queue resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusQueueResource> AddServiceBusQueue( this IResourceBuilder<AzureServiceBusResource> builder, string name, string? queueName = null) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. name string The name of the queue resource. queueName string? optional The name of the Service Bus Queue. If not provided, this defaults to the same value as name. Returns
IResourceBuilder<AzureServiceBusQueueResource> A reference to the ApplicationModel.IResourceBuilder`1. AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?) Section titled AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?) extension IResourceBuilder<AzureServiceBusSubscriptionResource> Adds an Azure Service Bus Subscription resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusSubscriptionResource> AddServiceBusSubscription( this IResourceBuilder<AzureServiceBusTopicResource> builder, string name, string? subscriptionName = null) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusTopicResource> The Azure Service Bus Topic resource builder. name string The name of the subscription resource. subscriptionName string? optional The name of the Service Bus Subscription. If not provided, this defaults to the same value as name. Returns
IResourceBuilder<AzureServiceBusSubscriptionResource> A reference to the ApplicationModel.IResourceBuilder`1. AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?) Section titled AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?) extension IResourceBuilder<AzureServiceBusTopicResource> Adds an Azure Service Bus Topic resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusTopicResource> AddServiceBusTopic( this IResourceBuilder<AzureServiceBusResource> builder, string name, string? topicName = null) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. name string The name of the topic resource. topicName string? optional The name of the Service Bus Topic. If not provided, this defaults to the same value as name. Returns
IResourceBuilder<AzureServiceBusTopicResource> A reference to the ApplicationModel.IResourceBuilder`1. AddSubscription(IResourceBuilder<AzureServiceBusResource>, string, string) Section titled AddSubscription(IResourceBuilder<AzureServiceBusResource>, string, string) extension IResourceBuilder<AzureServiceBusResource> Adds an Azure Service Bus Subscription resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> AddSubscription( this IResourceBuilder<AzureServiceBusResource> builder, string topicName, string subscriptionName) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. topicName string The name of the topic resource. subscriptionName string The name of the subscription. Returns
IResourceBuilder<AzureServiceBusResource> A reference to the ApplicationModel.IResourceBuilder`1. AddTopic(IResourceBuilder<AzureServiceBusResource>, string) Section titled AddTopic(IResourceBuilder<AzureServiceBusResource>, string) extension IResourceBuilder<AzureServiceBusResource> Adds an Azure Service Bus Topic resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> AddTopic( this IResourceBuilder<AzureServiceBusResource> builder, string name) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. name string The name of the topic resource. AddTopic(IResourceBuilder<AzureServiceBusResource>, string, string[]) Section titled AddTopic(IResourceBuilder<AzureServiceBusResource>, string, string[]) extension IResourceBuilder<AzureServiceBusResource> Adds an Azure Service Bus Topic resource to the application model.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> AddTopic( this IResourceBuilder<AzureServiceBusResource> builder, string name, string[] subscriptions) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> The Azure Service Bus resource builder. name string The name of the topic resource. subscriptions string[] The name of the subscriptions. RunAsEmulator(IResourceBuilder<AzureServiceBusResource>, Action<IResourceBuilder<AzureServiceBusEmulatorResource>>) Section titled RunAsEmulator(IResourceBuilder<AzureServiceBusResource>, Action<IResourceBuilder<AzureServiceBusEmulatorResource>>) extension IResourceBuilder<AzureServiceBusResource> Configures an Azure Service Bus resource to be emulated. This resource requires an
AzureServiceBusResource to be added to the application model. public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusResource> RunAsEmulator( this IResourceBuilder<AzureServiceBusResource> builder, Action<IResourceBuilder<AzureServiceBusEmulatorResource>>? configureContainer = null) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusResource> configureContainer Action<IResourceBuilder<AzureServiceBusEmulatorResource>> optional Remarks
This version of the package defaults to the tag of the / container image. The Azure Service Bus resource builder. Callback that exposes underlying container used for emulation to allow for customization. A reference to the
ApplicationModel.IResourceBuilder`1. The following example creates an Azure Service Bus resource that runs locally is an emulator and referencing that resource in a .NET project. var builder = DistributedApplication.CreateBuilder(args);
var serviceBus = builder.AddAzureServiceBus("myservicebus") .RunAsEmulator() .AddQueue("queue");
builder.AddProject<Projects.InventoryService>() .WithReference(serviceBus);
builder.Build().Run();WithConfiguration(IResourceBuilder<AzureServiceBusEmulatorResource>, Action<JsonNode>) Section titled WithConfiguration(IResourceBuilder<AzureServiceBusEmulatorResource>, Action<JsonNode>) extension IResourceBuilder<AzureServiceBusEmulatorResource> Alters the JSON configuration document used by the emulator.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusEmulatorResource> WithConfiguration( this IResourceBuilder<AzureServiceBusEmulatorResource> builder, Action<JsonNode> configJson) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusEmulatorResource> The builder for the AzureServiceBusEmulatorResource. configJson Action<JsonNode> A callback to update the JSON object representation of the configuration. Returns
IResourceBuilder<AzureServiceBusEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
Here is an example of how to configure the emulator to use a different logging mechanism:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureServiceBus("servicebusns") .RunAsEmulator(configure => configure .WithConfiguration(document => { document["UserConfig"]!["Logging"] = new JsonObject { ["Type"] = "Console" }; }); );WithConfigurationFile(IResourceBuilder<AzureServiceBusEmulatorResource>, string) Section titled WithConfigurationFile(IResourceBuilder<AzureServiceBusEmulatorResource>, string) extension IResourceBuilder<AzureServiceBusEmulatorResource> Copies the configuration file into an Azure Service Bus emulator resource.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusEmulatorResource> WithConfigurationFile( this IResourceBuilder<AzureServiceBusEmulatorResource> builder, string path) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusEmulatorResource> The builder for the AzureServiceBusEmulatorResource. path string Path to the file on the AppHost where the emulator configuration is located. Returns
IResourceBuilder<AzureServiceBusEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. WithHostPort(IResourceBuilder<AzureServiceBusEmulatorResource>, int?) Section titled WithHostPort(IResourceBuilder<AzureServiceBusEmulatorResource>, int?) extension IResourceBuilder<AzureServiceBusEmulatorResource> Configures the host port for the Azure Service Bus emulator is exposed on instead of using randomly assigned port.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusEmulatorResource> WithHostPort( this IResourceBuilder<AzureServiceBusEmulatorResource> builder, int? port) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusEmulatorResource> Builder for the Azure Service Bus emulator container port int? The port to bind on the host. If null is used, a random port will be assigned. Returns
IResourceBuilder<AzureServiceBusEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. WithProperties(IResourceBuilder<AzureServiceBusQueueResource>, Action<AzureServiceBusQueueResource>) Section titled WithProperties(IResourceBuilder<AzureServiceBusQueueResource>, Action<AzureServiceBusQueueResource>) extension IResourceBuilder<AzureServiceBusQueueResource> Allows setting the properties of an Azure Service Bus Queue resource.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusQueueResource> WithProperties( this IResourceBuilder<AzureServiceBusQueueResource> builder, Action<AzureServiceBusQueueResource> configure) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusQueueResource> The Azure Service Bus Queue resource builder. configure Action<AzureServiceBusQueueResource> A method that can be used for customizing the AzureServiceBusQueueResource. Returns
IResourceBuilder<AzureServiceBusQueueResource> A reference to the ApplicationModel.IResourceBuilder`1. WithProperties(IResourceBuilder<AzureServiceBusTopicResource>, Action<AzureServiceBusTopicResource>) Section titled WithProperties(IResourceBuilder<AzureServiceBusTopicResource>, Action<AzureServiceBusTopicResource>) extension IResourceBuilder<AzureServiceBusTopicResource> Allows setting the properties of an Azure Service Bus Topic resource.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusTopicResource> WithProperties( this IResourceBuilder<AzureServiceBusTopicResource> builder, Action<AzureServiceBusTopicResource> configure) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusTopicResource> The Azure Service Bus Topic resource builder. configure Action<AzureServiceBusTopicResource> A method that can be used for customizing the AzureServiceBusTopicResource. Returns
IResourceBuilder<AzureServiceBusTopicResource> A reference to the ApplicationModel.IResourceBuilder`1. WithProperties(IResourceBuilder<AzureServiceBusSubscriptionResource>, Action<AzureServiceBusSubscriptionResource>) Section titled WithProperties(IResourceBuilder<AzureServiceBusSubscriptionResource>, Action<AzureServiceBusSubscriptionResource>) extension IResourceBuilder<AzureServiceBusSubscriptionResource> Allows setting the properties of an Azure Service Bus Subscription resource.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<AzureServiceBusSubscriptionResource> WithProperties( this IResourceBuilder<AzureServiceBusSubscriptionResource> builder, Action<AzureServiceBusSubscriptionResource> configure) { // ... }}Parameters
builder IResourceBuilder<AzureServiceBusSubscriptionResource> The Azure Service Bus Subscription resource builder. configure Action<AzureServiceBusSubscriptionResource> A method that can be used for customizing the AzureServiceBusSubscriptionResource. Returns
IResourceBuilder<AzureServiceBusSubscriptionResource> A reference to the ApplicationModel.IResourceBuilder`1. WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[]) Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[]) extension IResourceBuilder<T> Assigns the specified roles to the given resource, granting it the necessary permissions on the target Azure Service Bus namespace. This replaces the default role assignments for the resource.
public static class AzureServiceBusExtensions{ public static IResourceBuilder<T> WithRoleAssignments<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureServiceBusResource> target, params ServiceBusBuiltInRole[] roles) { // ... }}Parameters
builder IResourceBuilder<T> The resource to which the specified roles will be assigned. target IResourceBuilder<AzureServiceBusResource> The target Azure Service Bus namespace. roles ServiceBusBuiltInRole[] The built-in Service Bus roles to be assigned. Returns
IResourceBuilder<T> The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments. Remarks
Assigns the AzureServiceBusDataSender role to the 'Projects.Api' project.
var builder = DistributedApplication.CreateBuilder(args);
var sb = builder.AddAzureServiceBus("bus");
var api = builder.AddProject<Projects.Api>("api") .WithRoleAssignments(sb, ServiceBusBuiltInRole.AzureServiceBusDataSender) .WithReference(sb);