{"id":1382,"library":"azure-mgmt-servicebus","title":"Azure Service Bus Management Client Library","description":"The `azure-mgmt-servicebus` library provides the client-side functionality for managing Azure Service Bus resources, such as namespaces, queues, and topics, through the Azure Resource Manager API. It is part of the broader Azure SDK for Python, currently at version 9.0.0, and follows a consistent release cadence with other Azure management libraries, typically updated monthly or bi-monthly with new API versions and features.","status":"active","version":"9.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/servicebus/azure-mgmt-servicebus","tags":["Azure","Service Bus","Management","Cloud","Microsoft","Messaging"],"install":[{"cmd":"pip install azure-mgmt-servicebus azure-identity","lang":"bash","label":"Install with identity provider"}],"dependencies":[{"reason":"Common Azure SDK utilities.","package":"azure-common","optional":false},{"reason":"Core utilities and HTTP pipeline for Azure SDKs.","package":"azure-core","optional":false},{"reason":"Azure-specific extensions for msrest.","package":"msrestazure","optional":false},{"reason":"Recommended credential provider for authenticating with Azure services.","package":"azure-identity","optional":false}],"imports":[{"symbol":"ServiceBusManagementClient","correct":"from azure.mgmt.servicebus import ServiceBusManagementClient"},{"note":"Old credential types are deprecated; use azure-identity for modern authentication.","wrong":"from azure.common.credentials import ServicePrincipalCredentials","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.servicebus import ServiceBusManagementClient\n\n# Set your Azure Subscription ID and Resource Group in environment variables or replace directly.\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\nresource_group_name = os.environ.get('AZURE_RESOURCE_GROUP_NAME', 'my-servicebus-rg')\nnamespace_name = os.environ.get('AZURE_SERVICEBUS_NAMESPACE', 'my-servicebus-namespace')\n\nif subscription_id == 'YOUR_SUBSCRIPTION_ID':\n    raise ValueError(\"Please set the AZURE_SUBSCRIPTION_ID environment variable.\")\n\n# Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a Service Bus Management Client\nservicebus_client = ServiceBusManagementClient(credential, subscription_id)\n\ntry:\n    # Example: List all Service Bus namespaces in a resource group\n    print(f\"Listing Service Bus namespaces in resource group '{resource_group_name}':\")\n    namespaces = servicebus_client.namespaces.list_by_resource_group(resource_group_name)\n    for ns in namespaces:\n        print(f\"  - {ns.name} (Location: {ns.location}, Status: {ns.status})\")\n\n    # Example: Get a specific Service Bus namespace (if it exists)\n    print(f\"\\nGetting Service Bus namespace '{namespace_name}':\")\n    try:\n        ns_details = servicebus_client.namespaces.get(resource_group_name, namespace_name)\n        print(f\"  Namespace '{ns_details.name}' found. Status: {ns_details.status}\")\n    except Exception as e:\n        print(f\"  Namespace '{namespace_name}' not found or error: {e}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then use `ServiceBusManagementClient` to list and retrieve Service Bus namespaces within a specified resource group. Ensure `AZURE_SUBSCRIPTION_ID` and `AZURE_RESOURCE_GROUP_NAME` environment variables are set for authentication and resource context."},"warnings":[{"fix":"Review the official migration guides for your specific previous version. Re-evaluate client instantiation, method calls, and how model objects are accessed. Consider using the `async` clients where appropriate for non-blocking I/O.","message":"Major versions of Azure Management SDKs, especially from v7 onwards, introduced significant breaking changes. These often include the separation of synchronous and asynchronous clients, changes to method signatures (e.g., keyword-only arguments), and updates to model object structures. Upgrading from versions older than 7.x.x typically requires substantial code modification.","severity":"breaking","affected_versions":"<7.0.0 to 7.0.0+"},{"fix":"If your goal is to send or receive messages, use `pip install azure-servicebus`. If you need to manage the infrastructure, use `azure-mgmt-servicebus`.","message":"This library (`azure-mgmt-servicebus`) is strictly for *managing* Service Bus resources (creating namespaces, queues, topics, etc.). It does *not* provide functionality for sending or receiving messages from Service Bus queues or topics. For data plane operations, you need to use the `azure-servicebus` library.","severity":"gotcha","affected_versions":"All"},{"fix":"Always use `azure-identity` for credential management. Ensure you have the `azure-identity` package installed and replace any direct credential instantiation with `DefaultAzureCredential()` or other appropriate `azure-identity` credential types.","message":"Authentication mechanisms have evolved. Older examples might use `ServicePrincipalCredentials` directly, which is now deprecated. The recommended approach is `azure-identity` (e.g., `DefaultAzureCredential`), which provides a unified way to authenticate across different Azure environments.","severity":"gotcha","affected_versions":"<7.0.0 to 7.0.0+"},{"fix":"When iterating over large result sets from list operations, be aware that the iterator might fetch items in batches. For fine-grained control or explicit pagination, consult the method's documentation for `by_page()` or similar options, especially in `async` contexts.","message":"Listing operations often return paginated iterators rather than a simple list. While these can often be iterated directly, for scenarios requiring explicit page-by-page processing (e.g., handling large result sets, tracking continuation tokens), you may need to use `by_page()` methods if available or handle the iterator carefully.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}