使用新的 Azure 服务总线 SDK (7.0.0),创建主题、订阅和授权规则的正确方法是什么?
With the new Azure service bus SDK (7.0.0), what's the proper way to create a topic, subscription, and authorization rule?
我正在使用 Python 3.8 和适用于 Python 的新 Azure SDK,特别是 azure-mgmt-servicebus 7.0.0 版本。在我以前的版本中,每当我需要创建服务总线主题、订阅和适当的授权规则时,我都可以
sb_client = self._get_sb_client()
authorization_rule_rights = [AccessRights.listen]
sb_client = self._get_sb_client()
sb_client.topics.create_or_update(
resource_group_name, namespace_name, topic_name, parameters=TOPIC_PARAMS)
sb_client.subscriptions.create_or_update(
resource_group_name, namespace_name, topic_name,
SB_SUBSCRIPTION_NAME, parameters=SUBSCRIPTION_PARAMS)
# Create auth rule
sb_client.topics.create_or_update_authorization_rule(
resource_group_name=resource_group_name,
namespace_name=namespace_name,
topic_name=topic_name,
authorization_rule_name=SB_SAS_POLICY_LISTEN,
parameters=authorization_rule_rights)
但是,使用新的 SDK,我的“create_or_update_authorization_rule”现在抛出
msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'list' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'list' object has no attribute 'get'
错误。新文档 -- https://docs.microsoft.com/en-us/python/api/overview/azure/servicebus?view=azure-python#service-bus-topics-and-subscriptions 没有详细说明如何创建主题,仅使用现有主题发送消息。使用最新的SDK,创建主题、订阅和授权规则的正确方法是什么?
据我所知,最新版本azure-mgmt-servicebus is 6.0.0。
要创建授权规则,您应该将 authorization_rule_rights
的值设置为 json
格式。
这是一个例子:
authorization_rule_rights= {
"rights": [
"Listen",
"Send"
]
}
result = sb_client.topics.create_or_update_authorization_rule(
resource_group_name=RESOURCE_GROUP,
namespace_name=NAMESPACE_NAME,
topic_name=TOPIC_NAME,
authorization_rule_name=AUTHORIZATION_RULE_NAME,
parameters=authorization_rule_rights)
更多授权规则的创建可以参考this doc.
话题创建参考this section。
创建订阅,参考this section。
我正在使用 Python 3.8 和适用于 Python 的新 Azure SDK,特别是 azure-mgmt-servicebus 7.0.0 版本。在我以前的版本中,每当我需要创建服务总线主题、订阅和适当的授权规则时,我都可以
sb_client = self._get_sb_client()
authorization_rule_rights = [AccessRights.listen]
sb_client = self._get_sb_client()
sb_client.topics.create_or_update(
resource_group_name, namespace_name, topic_name, parameters=TOPIC_PARAMS)
sb_client.subscriptions.create_or_update(
resource_group_name, namespace_name, topic_name,
SB_SUBSCRIPTION_NAME, parameters=SUBSCRIPTION_PARAMS)
# Create auth rule
sb_client.topics.create_or_update_authorization_rule(
resource_group_name=resource_group_name,
namespace_name=namespace_name,
topic_name=topic_name,
authorization_rule_name=SB_SAS_POLICY_LISTEN,
parameters=authorization_rule_rights)
但是,使用新的 SDK,我的“create_or_update_authorization_rule”现在抛出
msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'list' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'list' object has no attribute 'get'
错误。新文档 -- https://docs.microsoft.com/en-us/python/api/overview/azure/servicebus?view=azure-python#service-bus-topics-and-subscriptions 没有详细说明如何创建主题,仅使用现有主题发送消息。使用最新的SDK,创建主题、订阅和授权规则的正确方法是什么?
据我所知,最新版本azure-mgmt-servicebus is 6.0.0。
要创建授权规则,您应该将 authorization_rule_rights
的值设置为 json
格式。
这是一个例子:
authorization_rule_rights= {
"rights": [
"Listen",
"Send"
]
}
result = sb_client.topics.create_or_update_authorization_rule(
resource_group_name=RESOURCE_GROUP,
namespace_name=NAMESPACE_NAME,
topic_name=TOPIC_NAME,
authorization_rule_name=AUTHORIZATION_RULE_NAME,
parameters=authorization_rule_rights)
更多授权规则的创建可以参考this doc.
话题创建参考this section。
创建订阅,参考this section。