Home:ALL Converter>How to create topic, subscription and SAS policy in azure service bus namespace?

How to create topic, subscription and SAS policy in azure service bus namespace?

Ask Time:2020-12-08T14:36:03         Author:Harish

Json Formatter

I need to create topic, subscription and SAS policy for azure service bus namespace using shared access policy connectionstring. for that I have used "Microsoft.Azure.ServiceBus" NuGet package.(I am using this NuGet package because I am using .NET Core 2.1).

Note :- Namespace is already created in azure service bus.

What I have tried :-

Now, I can create topic and subscription using following code as

 public static async Task CreateTopicSubscriptionAndSASPolicy()
    {
        string ServiceBusConnectionString = "Endpoint=sb://servicebusnameone.servicebus.windows.net/;SharedAccessKeyName=xxxxx;xxxxxxxxxxxxxxxxxxxxxxx";
        string topic = "TopicOne";
        string subscriptionName = "SubOne";
        var client = new ManagementClient(ServiceBusConnectionString);

        if (!await client.TopicExistsAsync(topic))
        {
            await client.CreateTopicAsync(topic);
        }
        if (!await client.SubscriptionExistsAsync(topic, subscriptionName))
        {
            await client.CreateSubscriptionAsync(new SubscriptionDescription(topic, subscriptionName));
        }

        IEnumerable<AccessRights> accessRights = new[] { AccessRights.Send };
        SharedAccessAuthorizationRule sharedAccessAuthorizationRule = new SharedAccessAuthorizationRule("SendRule", accessRights);
        //TO DO Create SAS Policy....
    }

Now, I need to create SAS policy at namespace level but I am not sure how can I do it? I have also read following Microsoft documentation and stackoverflow question-answer

  1. https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-sas

  2. https://github.com/Huachao/azure-content/blob/master/articles/service-bus/service-bus-shared-access-signature-authentication.md

  3. Shared Access Policy Programatic Creation for Azure Service Bus

  4. Using SAS Token with Azure ServiceBus

  5. Azure Service Bus Shared Access Signature Generation

Question :-

  1. How can I create SAS policy in azure service bus namespace?
  2. There is any way to configure topic/subscriptions while creating? (because while I create topic using above given code it create topic with Max size 1024 MB but I need to set it 5120 MB)?
  3. Apart from this there is any better way(best practice) to create topic, subscription and SAS policy using connection string in .Net Core 2.1?

Note:- Any working example is very helpful to clear understanding.

Author:Harish,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65194186/how-to-create-topic-subscription-and-sas-policy-in-azure-service-bus-namespace
yy