Dynamically provision Service Bus namespaces and entities

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

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 leverage 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.

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.

However, if you are already using a Service Bus client library for service specific operations like send and receive messages and you need to manage Service Bus entities as well, then using the same library might be more convenient for you. The client libraries have a ServiceBusAdministrationClient (called ServiceBusManagementClient in the older libraries) that provides a subset of the management features provided by the Azure Resource Manager-based libraries. It must be emphasized that while the Azure Resource Manager-based libraries allow you to manage both Service Bus namespaces and entities, the client libraries only allow you to manage entities in an existing namespace but not 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 do not support connection strings.

Language Package Documentation Samples
.NET Azure.ResourceManager.ServiceBus API reference for Microsoft.Azure.Management.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 is 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 that are used for operations like send and receive messages can also be used to manage queues, topics, subscriptions, and rules in an existing Service Bus namespace. This feature is available via the ServiceBusAdministrationClient in the latest libraries and via the ServiceBusManagementClient in the older libraries. It is highly recommended that you use the latest libraries.

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

Legacy Service Bus libraries

Language Package Documentation Samples
.NET Microsoft.Azure.ServiceBus ManagementClient .NET
Java azure-mgmt-servicebus ManagementClientAsync, ManagementClient Java

On 30 September 2026, we'll retire the Azure Service Bus SDK libraries WindowsAzure.ServiceBus, Microsoft.Azure.ServiceBus, and com.microsoft.azure.servicebus, which don't conform to Azure SDK guidelines. We'll also end support of the SBMP protocol, so you'll no longer be able to use this protocol after 30 September 2026. Migrate to the latest Azure SDK libraries, which offer critical security updates and improved capabilities, before that date.

Although the older libraries can still be used beyond 30 September 2026, they'll no longer receive official support and updates from Microsoft. For more information, see the support retirement announcement.

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