I have implemented an Azure Service Bus REST API client. At the moment I am building xUnit tests for my REST project and need to create a Queue with a name provided by the test, send messages with the REST client and then delete the Queue with that specific name.
One of my requirements are to specify a Shared Access Policy for the newly created Queue with only Send permissions programmatically but I can't find anything online that suggests that this is possible.
So far I have this
TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider("MyBusAccessPolicy", "XXXXXXXXXXXXXXXX");
NamespaceManager namespaceManager = new NamespaceManager(ServiceBusEnvironment.CreateServiceUri("sb", _serviceNamespace, string.Empty), credentials);
QueueDescription queueDescription = await namespaceManager.CreateQueueAsync(queueName);
How would I proceed to create the Shared Access Policy specifically for that queue if even possible?
Neil,
Something like this should work:
string queuePolicyName = "SendPolicy";
string queuePrimaryKey = SharedAccessAuthorizationRule.GenerateRandomKey();
QueueDescription queueDescription = new QueueDescription(queueName);
SharedAccessAuthorizationRule queueSharedAccessPolicy = new SharedAccessAuthorizationRule(queuePolicyName, queuePrimaryKey, new[] { AccessRights.Send });
queueDescription.Authorization.Add(queueSharedAccessPolicy);
await _namespaceManager.CreateQueueAsync(queueDescription);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With