在适用于 .NET 的 Azure 管理库中创建具有多个声明的 Azure 服务总线策略
Create Azure Service Bus policy with multiple claims in Azure Management libraries for .NET
我将 Azure Management libraries for .NET 与 Azure 服务总线一起使用。我的 objective 是创建一个带有 Send 和 Listen 声明的共享访问策略。我可以在 Azure 门户中执行此操作。
IServiceBusNamespace serviceBus = ...
IBlank policyDefinition = serviceBus.AuthorizationRules.Define("MySendAndListenPolicy2");
从 IBlank
我可以呼叫 WithListeningEnabled()
或 WithSendingEnabled()
。 return 和 IWithCreate
,我只能从中创建规则(即 Create()
和 CreateAsync()
。似乎没有配置两者的选项 发送和收听。
如何使用 Azure Management .NET SDK 创建带有 Send 和 Listen 的策略?
我是通过使用流利 API 的 Inner 对象实现的。
// using Microsoft.Azure.Management.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent.Models;
string policyName = "ListenAndSendPolicy";
// Define the claims
IList<AccessRights?> rights = new List<AccessRights?>();
rights.Add(AccessRights.Send);
rights.Add(AccessRights.Listen);
// Create the rule
SharedAccessAuthorizationRuleInner rule = await serviceBus.AuthorizationRules.Inner.CreateOrUpdateAuthorizationRuleAsync(
serviceBus.ResourceGroupName,
serviceBus.Name,
policyName,
rights);
// Get the policy
policy = await serviceBus.AuthorizationRules.GetByNameAsync(policyName);
这已成功创建策略
我将 Azure Management libraries for .NET 与 Azure 服务总线一起使用。我的 objective 是创建一个带有 Send 和 Listen 声明的共享访问策略。我可以在 Azure 门户中执行此操作。
IServiceBusNamespace serviceBus = ...
IBlank policyDefinition = serviceBus.AuthorizationRules.Define("MySendAndListenPolicy2");
从 IBlank
我可以呼叫 WithListeningEnabled()
或 WithSendingEnabled()
。 return 和 IWithCreate
,我只能从中创建规则(即 Create()
和 CreateAsync()
。似乎没有配置两者的选项 发送和收听。
如何使用 Azure Management .NET SDK 创建带有 Send 和 Listen 的策略?
我是通过使用流利 API 的 Inner 对象实现的。
// using Microsoft.Azure.Management.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent.Models;
string policyName = "ListenAndSendPolicy";
// Define the claims
IList<AccessRights?> rights = new List<AccessRights?>();
rights.Add(AccessRights.Send);
rights.Add(AccessRights.Listen);
// Create the rule
SharedAccessAuthorizationRuleInner rule = await serviceBus.AuthorizationRules.Inner.CreateOrUpdateAuthorizationRuleAsync(
serviceBus.ResourceGroupName,
serviceBus.Name,
policyName,
rights);
// Get the policy
policy = await serviceBus.AuthorizationRules.GetByNameAsync(policyName);
这已成功创建策略