2
votes

I'm using newest Azure java sdk(version 0.6), but I found I have problems when I use service bus configuration "configureWithConnectionString" function. Here is my code below,

//get config
string connectionString = "Endpoint=sb://testservicebusnamespace.servicebus.windows.net/;SharedAccessKeyName=MySharedAccessKey;SharedAccessKey=<this is secret not show>";
config = new Configuration();
ServiceBusConfiguration.configureWithConnectionString(null, config, connectionString);

//create service
service = ServiceBusService.create(config);

And I get connection String from my service bus namespace portal in Azure. But When I run this code, it throws an exception "The key 'SharedAccessKeyName' is not valid for this connection string".

I don't know what's the problem, because I get the connection from Azure portal, and I've checked its content(the SharedAccessKeyName, SharedAccessKey), they are right.

So could anyone help me? Is it my problem or this SDK needs update(because I've heard portal already uses SAS, but SDK still uses ACS to authenticate)?

Thanks very much.

2

2 Answers

0
votes

It looks like Java Azure SDK(0.6.0) still uses ACS to authenticate. See this github issue comments:

the current SDK works with service bus namespace with ACS auth mode, but not new created servicebus namespace which use SAS token auth mode. we will investigate this issue

and

One workaround is to create the service bus namespace via PowerShell. This seems to enable the ACS auth mode by default. Command is:

New-AzureSBNameSpace -Name MyNameSpace -Location "West Europe"

Take a note of the "DefaultKey" you get after running the command. You need to use that with the ServiceBusConfiguration and I'm not sure if that is available via the Azure management portal. Use "owner" as the authenticationName parameter to the configureWithWrapAuthentication.

0
votes

I'm adding this answer, because I thought I was doomed. But found a new library.

This dependency (which 0.5.0 was latest version when I wrote this post)......gives you the issue.

          <dependency>
                 <groupId>com.microsoft.windowsazure</groupId>
                 <artifactId>microsoft-azure-api-servicebus</artifactId>
                 <version>0.5.0</version>
          </dependency>

Microsoft slightly altered the groupid. Here is a dependency that seems much more update to date.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-servicebus</artifactId>
    <version>0.9.7</version>
</dependency>

Maven link here : https://search.maven.org/#artifactdetails%7Ccom.microsoft.azure%7Cazure-servicebus%7C0.9.7%7Cjar

So its an old question. But hopefully this points somebody in the right direction.