无法使用 CreateTopicAsync 在 ServiceBus 中创建新主题
Cannot create a new Topic in ServiceBus with CreateTopicAsync
我正在尝试使用库 Microsoft.Azure.ServiceBus.Management 的方法 CreateTopicAsync 创建一个新主题(然后是订阅)。
连接字符串正确,如果我通过 Azure 门户创建主题,我可以发送和接收消息。
我究竟做错了什么?感谢任何帮助。
var managementClient = new ManagementClient(ServiceBusConnectionString);
bool topicExists = await managementClient.TopicExistsAsync(TopicName).ConfigureAwait(false);
if (!topicExists) {
TopicDescription td = new TopicDescription(TopicName);
td.MaxSizeInMB = 1024;
td.DefaultMessageTimeToLive = new TimeSpan(2, 0, 0, 0);
await managementClient.CreateTopicAsync(td).ConfigureAwait(false);
}
尽管服务总线 ConnectionString 可能是正确的,但要使您的应用程序能够创建主题,它需要具有 Manage
权利(声明)。
取自Service Bus access control with Shared Access Signatures:
For each authorization policy rule, you decide on three pieces of information: name, scope, and rights. The name is just that; a unique name within that scope. The scope is easy enough: it's the URI of the resource in question. For a Service Bus namespace, the scope is the fully qualified domain name (FQDN), such as https://.servicebus.windows.net/.
The rights conferred by the policy rule can be a combination of:
- 'Send' - Confers the right to send messages to the entity
- 'Listen' - Confers the right to listen (relay) or receive (queue, subscriptions) and all related message handling
- 'Manage' - Confers the right to manage the topology of the namespace, including creating and deleting entities
The 'Manage' right includes the 'Send' and 'Receive' rights.
我正在尝试使用库 Microsoft.Azure.ServiceBus.Management 的方法 CreateTopicAsync 创建一个新主题(然后是订阅)。 连接字符串正确,如果我通过 Azure 门户创建主题,我可以发送和接收消息。 我究竟做错了什么?感谢任何帮助。
var managementClient = new ManagementClient(ServiceBusConnectionString);
bool topicExists = await managementClient.TopicExistsAsync(TopicName).ConfigureAwait(false);
if (!topicExists) {
TopicDescription td = new TopicDescription(TopicName);
td.MaxSizeInMB = 1024;
td.DefaultMessageTimeToLive = new TimeSpan(2, 0, 0, 0);
await managementClient.CreateTopicAsync(td).ConfigureAwait(false);
}
尽管服务总线 ConnectionString 可能是正确的,但要使您的应用程序能够创建主题,它需要具有 Manage
权利(声明)。
取自Service Bus access control with Shared Access Signatures:
For each authorization policy rule, you decide on three pieces of information: name, scope, and rights. The name is just that; a unique name within that scope. The scope is easy enough: it's the URI of the resource in question. For a Service Bus namespace, the scope is the fully qualified domain name (FQDN), such as https://.servicebus.windows.net/.
The rights conferred by the policy rule can be a combination of:
- 'Send' - Confers the right to send messages to the entity
- 'Listen' - Confers the right to listen (relay) or receive (queue, subscriptions) and all related message handling
- 'Manage' - Confers the right to manage the topology of the namespace, including creating and deleting entities
The 'Manage' right includes the 'Send' and 'Receive' rights.