Edit

Dynamically create Service Bus namespaces and entities

Azure Service Bus provides libraries to help dynamically create Service Bus namespaces and entities. It enables complex deployments and messaging scenarios and makes it possible to programmatically determine what entities to create.

Overview

There are two approaches you can take to manage Azure Service Bus resources programmatically. The first is to use the Azure Resource Manager-based libraries, which allow you to manage namespaces, queues, topics, subscriptions, rules, and SAS policies. Azure Resource Manager-based libraries have support for authentication through Microsoft Entra ID, but not through connection strings. The second approach is to use the same Service Bus client libraries that you use to send and receive messages. The client libraries also provide APIs to help you manage queues, topics, subscriptions, and rules in an existing namespace. They have support for authentication with connection strings. When deciding which approach to take, consider the following points.

The Azure Resource Manager-based libraries offer the same functionality as Azure portal, CLI, and PowerShell when it comes to managing Service Bus namespaces and entities like queues, topics, subscriptions, etc. If you have been using Azure portal, CLI, or PowerShell for your management operations and would like a dynamic way of doing that, then these libraries might be a better choice for you.

If you're already using a Service Bus client library to send and receive messages, use its ServiceBusAdministrationClient to manage entities in the same application. This client manages queues, topics, subscriptions, and rules in an existing namespace. Use an Azure Resource Manager-based library to manage the namespace itself.

Manage using Azure Resource Manager-based libraries

The Azure Resource Manager-based libraries allow you to manage namespaces, queues, topics, subscriptions, rules, and SAS policies. They support authentication with Microsoft Entra ID only; they don't support connection strings.

Language Package Documentation Samples
.NET Azure.ResourceManager.ServiceBus API reference for Azure.ResourceManager.ServiceBus .NET
Java azure-resourcemanager-servicebus API reference for com.azure.resourcemanager.servicebus Java
JavaScript @Azure/arm-servicebus API reference for @Azure/arm-servicebus
Python azure-mgmt-servicebus API reference for azure-mgmt-servicebus

Fluent .NET and Java libraries

There's a Fluent version of the Azure Resource Manager-based libraries.

Language Package Documentation
.NET Microsoft.Azure.Management.ServiceBus.Fluent API reference for Microsoft.Azure.Management.ServiceBus.Fluent
Java azure-resourcemanager-servicebus API reference for com.azure.resourcemanager.servicebus.fluent

Manage using Service Bus client libraries

Service Bus client libraries provide a ServiceBusAdministrationClient to manage queues, topics, subscriptions, and rules in an existing Service Bus namespace.

Latest Service Bus libraries

Language Package Documentation Samples
.NET Azure.Messaging.ServiceBus ServiceBusAdministrationClient .NET
Java azure-messaging-servicebus ServiceBusAdministrationAsyncClient, ServiceBusAdministrationClient Java
JavaScript @Azure/service-bus ServiceBusAdministrationClient JavaScript/TypeScript
Python azure-servicebus ServiceBusAdministrationClient Python

Next steps

  • Send messages to and receive messages from queue using the latest Service Bus library: .NET, Java, JavaScript, Python
  • Send messages to topic and receive messages from subscription using the latest Service Bus library: .NET, Java, JavaScript, Python