I'm using Python 3.8 with azure-mgmt-servicebus= v. 1.0.0. Using the ServiceBusManagementClient, I'm able to create a topic and subscription on my service bus, using
from azure.mgmt.servicebus import ServiceBusManagementClient
...
credential = ServicePrincipalCredentials(self._client_id, self._client_secret, tenant=self._tenant)
sb_client = ServiceBusManagementClient(credential, self._subscription)
sb_client.topics.create_or_update(resource_group_name, namespace_name, topic_name, parameters={})
sb_client.subscriptions.create_or_update(resource_group_name, namespace_name, topic_name, SB_SUBSCRIPTION_NAME, parameters={})
However, I am having a more challenging time sending a message on that topic. I tried this
credential = ServicePrincipalCredentials(self._client_id, self._client_secret, tenant=self._tenant)
sb_client = ServiceBusManagementClient(credential, self._subscription)
topic_client = sb_client.get_topic(topic_name)
topic_client.send(msg)
But I get an error "Instance of 'ServiceBusManagementClient' has no 'get_topic' member". How do I use the ServiceBusManagementClient to send a message on a topic?
To answer directly,
ServiceBusManagementClientis not for sending a message to a topic.But have no fear! The issue here is that you're utilizing functionality from two distinct ServiceBus clients that do not exist in the same package, and this can be sorted out.
ServiceBusManagementClientis part of theazure-mgmt-servicebuspackage, and allows creation, administration, management, etc. (this is wherecreate_or_updateand friends come in)ServiceBusClientis part of theazure-servicebuspackage, and provides the sending/receiving functionality you seem to want after viaget_topicandsend. (this is the syntax from version 0.5*)So to be clear, one would not use the
ServiceBusManagementClientto send messages, only do management.ServiceBusClientis the solution, as seen in this sample.