c# - 在 .NET 的 Azure 管理库中创建具有多个声明的 Azure 服务总线策略
问题描述
我将Azure 管理库用于 .NET和 Azure 服务总线。我的目标是创建一个包含Send and Listen声明的共享访问策略。我可以在 Azure 门户中执行此操作。
IServiceBusNamespace serviceBus = ...
IBlank policyDefinition = serviceBus.AuthorizationRules.Define("MySendAndListenPolicy2");
从IBlank
我可以打电话WithListeningEnabled()
或WithSendingEnabled()
。两者都返回一个IWithCreate
,我只能从中创建规则 (即Create()
和CreateAsync()
。似乎没有配置Send和Listen的选项。
如何使用 Azure 管理 .NET SDK创建包含发送和侦听的策略?
解决方案
我通过使用fluent API的内部对象实现了这一点。
// 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);
这成功创建了策略
推荐阅读
- javascript - Stripe:是否可以创建具有幂等性的直接充电
- artificial-intelligence - 2 个具有 Minimax 的竞争性 AI
- reactjs - 如何在反应中获取当前页码onPagechange函数
- javascript - 根据类更改 img src
- javascript - 为什么在JS中没有提升变量定义而是函数
- ios - Clang + iOS + 汇编程序跳转:错误“符号上不支持重定位”
- java - Kotlin 使用内置 ECB Java 实现实现 AES-CBC
- pandas - 如何在熊猫中将多列设置为索引
- php - Laravel Artisan::call() 如果失败则捕获异常
- javascript - Discord bot 来自 PC 的普通用户名,但来自手机的 @invalid-user