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
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-sas
https://github.com/Huachao/azure-content/blob/master/articles/service-bus/service-bus-shared-access-signature-authentication.md
Shared Access Policy Programatic Creation for Azure Service Bus
Using SAS Token with Azure ServiceBus
Azure Service Bus Shared Access Signature Generation
Question :-
- How can I create SAS policy in azure service bus namespace?
- 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)?
- 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.