我正在创建一个应用程序,该应用程序需要创建和删除对 Azure 服务总线中已创建主题的订阅。
我的共享访问令牌是否需要管理该主题的权限才能创建和删除订阅?我做了一些初步的谷歌搜索,我找不到的文章都没有显示三个角色(管理、发送、监听)与订阅实体的相关性。
谢谢!
更新 我直接在主题上创建了共享访问策略,然后我编写了以下代码来访问主题,创建订阅,然后通过 IDisposable 接口取消/处理它们:
public class SubscriptionHandler : IDisposable
{
protected NamespaceManager SubManager { get; set; }
protected SubscriptionDescription SubDetails { get; set; }
public SubscriptionClient Client { get; }
public SubscriptionHandler(AuthDetails details)
{
try
{
var connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
SubManager = NamespaceManager.CreateFromConnectionString(connectionString);
SubDetails = new SubscriptionDescription("topic", $"record{details.ID}.Other{details.OtherID}");
if (!SubManager.SubscriptionExists(SubDetails.TopicPath, SubDetails.Name))
{ //setting subscription to receive all bookings that are for the given businessID
SubManager.CreateSubscription(SubDetails, new SqlFilter($"ID = {details.ID}"));
}
Client = SubscriptionClient.CreateFromConnectionString(connectionString, SubDetails.TopicPath, SubDetails.Name);
}catch (Exception ex)
{
throw;
}
}
public void Dispose()
{
if(Client != null)
{
Client.Close(); // telling subscription we are no longer going to recieve messages
}
if (SubManager != null && SubManager.SubscriptionExists(SubDetails.TopicPath, SubDetails.Name))
{
SubManager.DeleteSubscription(SubDetails.TopicPath, SubDetails.Name);
}
}
但是,我仍然收到未经授权的异常
SubManager.CreateSubscription(SubDetails, new SqlFilter($"ID = {details.ID}")); 称呼。我从 SharedAccessPolicy 连接字符串中复制了连接字符串,然后删除了 EntityPath 名称值对......我做错了什么?