| title | Programmatically manage Azure Service Bus namespaces and entities |
|---|---|
| description | This article explains how to dynamically or programmatically create Service Bus namespaces and entities. |
| ms.topic | article |
| ms.date | 12/04/2025 |
| ms.devlang | csharp |
| ms.custom | devx-track-arm-template |
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.
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.
However, if you're 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.
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 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 |
There's a Fluent version of the Azure Resource Manager-based 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.
| 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 |
| Language | Package | Documentation | Samples |
|---|---|---|---|
| .NET | Microsoft.Azure.ServiceBus | ManagementClient | .NET |
| Java | azure-mgmt-servicebus | ManagementClientAsync, ManagementClient | Java |
[!INCLUDE service-bus-track-0-and-1-sdk-support-retirement]
- 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