How to Create Queue in Windows Azure?

2020-06-30 05:23发布

I am using below code to create queue, using SharedSecretTokenProvider. However I am not able to supply correct values of managerName & managerKey value form windows azure portal.

This results in Http 401 Unauthorized exception. How do I resolve this error?

const string queueName = "thequeue";
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
    ConfigurationManager.AppSettings["managerName"],
    ConfigurationManager.AppSettings["managerKey"]);

Uri uri = ServiceBusEnvironment.CreateServiceUri("http", "MyNamespace" , string.Empty);
NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);

QueueDescription qd = namespaceManager.CreateQueue(new QueueDescription(queueName)
{
    DefaultMessageTimeToLive = TimeSpan.FromMinutes(15),
    DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10),
    LockDuration = TimeSpan.FromMinutes(2),
    EnableBatchedOperations = true,
    EnableDeadLetteringOnMessageExpiration = true,
    RequiresDuplicateDetection = true
});

enter image description here

2条回答
贼婆χ
2楼-- · 2020-06-30 05:51

I had tried this a couple of times with your code before I realized the problem. You are using the SharedSecretTokenProvider which will go to ACS thinking it has an issuer and a key. Since you are trying to use the SAS you'll want to use a CreateSharedAccessSignatureTokenProvider instead.

Swap that out and provide the key and keyName and you should be good.

Also, Viperguynaz is correct, you should use the "sb" instead of http as well. It was failing before it reached there because the token provider was correctly declining you access since it didn't understand the key and keyname you were passing for what it thought was the issuer and key that ACS uses.

查看更多
Root(大扎)
3楼-- · 2020-06-30 06:13

Start with ServiceBusEnvironment.CreateServiceUri Method. Note that Service Bus endpoint URIs must always use the “sb://” protocol; for example sb://contoso.servicebus.windows.net/helloservicebus.

Uri address = ServiceBusEnvironment.CreateServiceUri("sb", "contoso", "helloservicebus");

Get your URI inputs set correctly and you should be in business.

查看更多
登录 后发表回答