Freigeben über


Unable to Create Topic/Queues within Service Bus with Java SDK

You have been trying to create a Topic within Service Bus, by following the documentation at

 https://azure.microsoft.com/en-us/documentation/articles/service-bus-java-how-to-use-topics-subscriptions/

Configuration config =
ServiceBusConfiguration.configureWithWrapAuthentication(
"angshuman-servicebus-ns",
"RootManageSharedAccessKey",
"P9DGWyPAqpKaRZf8KAEzLnApGTaGl9qkkQ/f4lMD5wL=",
".servicebus.windows.net",
"-sb.accesscontrol.windows.net/WRAPv0.9");
ServiceBusContract service = ServiceBusService.create(config);
TopicInfo topicInfo = new TopicInfo("TestTopicAngshu");

try
{
CreateTopicResult result = service.createTopic(topicInfo);
}

catch (ServiceException e) {
System.out.print("ServiceException encountered: ");
System.out.println(e.getMessage());
System.exit(-1);
}

But it fails with the error message -

Dec 15, 2014 4:52:27 PM com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor processCatch
WARNING: com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: angshuman-servicebus-ns-sb.accesscontrol.windows.net
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: angshuman-servicebus-ns-sb.accesscontrol.windows.net
ServiceException encountered: com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: angshuman-servicebus-ns-sb.accesscontrol.windows.net
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
at com.microsoft.windowsazure.core.pipeline.jersey.ClientFilterRequestAdapter.handle(ClientFilterRequestAdapter.java:33)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
at com.microsoft.windowsazure.services.servicebus.implementation.WrapRestProxy.wrapAccessToken(WrapRestProxy.java:52)
at com.microsoft.windowsazure.services.servicebus.implementation.WrapTokenManager.getAccessToken(WrapTokenManager.java:90)
at com.microsoft.windowsazure.services.servicebus.implementation.WrapFilter.getWrapToken(WrapFilter.java:55)
at com.microsoft.windowsazure.services.servicebus.implementation.WrapFilter.handle(WrapFilter.java:35)
at com.microsoft.windowsazure.core.pipeline.jersey.ClientFilterRequestAdapter.handle(ClientFilterRequestAdapter.java:33)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.put(WebResource.java:537)
at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.createTopic(ServiceBusRestProxy.java:401)
at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor.createTopic(ServiceBusExceptionProcessor.java:267)
at com.microsoft.phones.tuberia.servicebus.ServiceBusUtils.main(ServiceBusUtils.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Caused by: java.net.UnknownHostException: ravia-servicebus-ns-sb.accesscontrol.windows.net
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:234)
at com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:117)
at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutputStream.java:89)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at java.io.BufferedWriter.flush(BufferedWriter.java:254)
at com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:191)
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:128)
at com.sun.jersey.core.impl.provider.entity.BaseFormProvider.writeTo(BaseFormProvider.java:109)
at com.sun.jersey.core.impl.provider.entity.FormProvider.writeTo(FormProvider.java:88)
at com.sun.jersey.core.impl.provider.entity.FormProvider.writeTo(FormProvider.java:58)
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:213)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
... 22 more

If I ping the Service Bus endpoint I do get the result so it’s provisioned. It’s the ACS buddy namespace for Service Bus that is giving error.

C:\Users\annayak>nslookup angshuman-servicebus-ns.servicebus.windows.net

Non-authoritative answer:
Name: ns-sb2-prod-bl3-003.cloudapp.net
Address: 191.234.30.171
Aliases: angshuman-servicebus-ns.servicebus.windows.net

C:\Users\annayak>nslookup angshuman-servicebus-ns-sb.accesscontrol.windows.net

DNS request timed out. timeout was 2 seconds.

If you have created the Service Bus recently it will not have the ACS buddy namespace. The way to get an ACS namespace is using PowerShell and I have documented it on this blog

https://blogs.msdn.com/b/cie/archive/2014/08/29/service-bus-namespace-creation-on-portal-no-longer-has-acs-connection-string.aspx

If you are on Linux you can try the following option to create the buddy ACS namespace.

The ACS method.

In this way there is no need to change the existing sample. Use Azure CLI for Linux by getting the latest version of Node.JS and then use NPM to install.  

https://azure.microsoft.com/en-us/documentation/articles/command-line-tools/#Commands_to_manage_service_bus

Command to create SB with ACS - https://azure.microsoft.com/en-us/documentation/articles/command-line-tools/#Commands_to_manage_service_bus

Recommended Approach

The current Java SDK installs the 0.6.0 release of Service Bus.

clip_image001

It doesn’t have the required method to deal with SAS.

clip_image003

So I checked on GIT and found that in version 0.7.0 we have the following method which can be used for SAS.

ServiceBusConfiguration.configureWithSASAuthentication("my-namespace", "my-key-name", "my-secret-key", ".servicebus.windows.net");

Details - https://github.com/Azure/azure-sdk-for-java/blob/master/serviceBus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusCreationTest.java

I download the latest SDK from https://github.com/Azure/azure-sdk-for-java and it has file with the class. If the code is built using the Service Bus 0.7.0 classes it will be able to use the new method ServiceBusConfiguration.configureWithSASAuthentication that supports SAS authentication.

Angshuman Nayak

Comments

  • Anonymous
    May 20, 2015
    Hi Angshuman,We are facing a similar issue as detailed in - social.msdn.microsoft.com/.../error-in-storm-spout-reading-from-service-bus-queueAs described here in your post, have updated the Azure library.Prior to this the exception received was --> "Caused by: com.microsoft.windowsazure.services.core.utils.ConnectionStringSyntaxException: The key 'SharedAccessKeyName' is not valid for this connection string".This exception got resolved but currently a new exception has arised --> "19657 [Thread-10-sb-queue-reader] ERROR backtype.storm.util - Async loop died!"Can you please hep us in pointing out as to where we are going wrong.Thanks!!