Reputation: 89
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
URL,
"RootManageSharedAccessKey",
token,
".servicebus.windows.net"
);
This is the code for configuration for java service bus implementation. I am interested in passing a shared access signature not a shared access key. I am not sure if this implementation for the java azure sdk supports this. How exactly would I do this. I keep getting a 401-unauthorized error when I use the shared access signature token in the token variable. Any ideas?
Upvotes: 0
Views: 1459
Reputation: 531
I can see that you created a Configuration object here. Normally we use it to creat a topic in Java, eg:
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
"namespace",
"sasKeyName",
"sasKey",
"serviceBusRootUri"
);
ServiceBusContract service = ServiceBusService.create(config);
TopicInfo topicInfo = new TopicInfo("TestTopic");
CreateTopicResult result = service.createTopic(topicInfo);
or to create a queue, eg:
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
"namespace",
"sasKeyName",
"sasKey",
"serviceBusRootUri"
);
ServiceBusContract service = ServiceBusService.create(config);
QueueInfo queueInfo = new QueueInfo("TestQueue");
CreateQueueResult result = service.createQueue(queueInfo);
and also we can create them by shared access signature: create a topic(c#)
Uri uri = ServiceBusEnvironment.CreateServiceUri("sb", "namespace", string.Empty);
string name = "sasKeyName";
string key = "sasKey";
TokenProvider tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(name, key);
NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);
namespaceManager.CreateTopic("DataCollectionTopic");
create a queue(c#):
Uri uri = ServiceBusEnvironment.CreateServiceUri("sb",
"namespace", string.Empty);
string name = "sasKeyName";
string key = "sasKey";
TokenProvider tokenProvider =
TokenProvider.CreateSharedAccessSignatureTokenProvider(name, key);
NamespaceManager namespaceManager =
new NamespaceManager(uri, tokenProvider);
namespaceManager.CreateQueue("DataCollectionQueue");
The namespace, sasKeyName, sasKey are configured in portal just as what Perter showed.
Upvotes: 0
Reputation: 24148
According to the source code of Azure Service Bus SDK for Java, the four arguments for the function configureWithSASAuthentication
should be the namespace
, sasKeyName
, sasKey
& serviceBusRootUri
(default pass ".servicebus.windows.net").
The namespace
, sasKeyName
& sasKey
you can find them via click the CONNECTION INFORMATION
button at the bottom of your service bus, please see the figures below.
Fig 1. The CONNECTION INFORMATION
button at the bottom of the service bus page
Fig 2. Copy the CONNECTION STRING
and extract the namespace, sasKeyName & sasKey
For example, the connection string is Endpoint=sb://abc-ns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=ABCdefg123!@#=
, then the namespace
, sasKeyName
, sasKey
are separately abc-ns
, RootManageSharedAccessKey
, ABCdefg123!@#=
.
So the code should be as below.
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
"abc-ns",
"RootManageSharedAccessKey",
"ABCdefg123!@#=",
".servicebus.windows.net"
);
And you can also find them at the CONFIGURE
tab of your service bus page, please see the figure below.
Upvotes: 3