0

I'm writting an Android App and connect to Azure Service bus - Topic. I write code to connect to existing namespace like this tutorial https://azure.microsoft.com/en-us/documentation/articles/service-bus-java-how-to-use-topics-subscriptions/

Configuration config = ServiceBusConfiguration.configureWithSASAuthentication(
  "HowToSample",
  "RootManageSharedAccessKey",
  "SAS_key_value",
  ".servicebus.windows.net"
  );

ServiceBusContract service = ServiceBusService.create(config);

But it throw an exception at ServiceBusContract service = ServiceBusService.create(config);. It said "java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.services.serviceBus.ServiceBusContract I looked up some way to fix it but not ok. So i use REST API to connect same this tutorial REST API AZURE

It can run and sent message to Azure Service Bus - Topic. Now i want to write a method use to get message from this Topic's Subcription. Use Rest API like that

String url = "https://smarthomethesis.servicebus.windows.net/light_1/Subscriptions/LightSubscription/messages/head?timeout=60";

HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);

// Add header
String token = generateSasToken(new URI(uri));

get.setHeader("Authorization", token);
System.out.println("Llamando al post");
HttpResponse response = client.execute(get);

HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");

But it can't get message, responseString show

"<Error><Code>400</Code><Detail>The request is not supported for the supplied api-version ''. TrackingId:d7624c10-4fc9-43d6-b092-880947e3b820_G31,TimeStamp:1/10/2016 3:43:44 PM</Detail></Error>"

I don't know why it isn't supported. Can you help me. Thank you

Community
  • 1
  • 1

1 Answers1

0

According to your code in Azure Java SDK, the issue was caused by using incorrect namespace, sasKeyName & sasKey. In the reference doc, the namespace HowToSample & SAS key SAS_key_value were created by the author, that be different from yours.

So you need to replace them with the namespace & SAS key value of your service bus created. You can find them on Azure portal or new portal.

For the Service Bus REST API, try to add the api-version in the query string for the Peek-Lock Message API, please note the content from the reference doc https://msdn.microsoft.com/en-us/library/azure/hh780771.aspx.

Version and server overview

Following Azure guidelines, REST APIs now support versioning. By default, passing no version indicates current service behavior. Any changes in existing REST APIs require providing an api-version value as the query string.

Version “2012-03”,“2012-08”,“2013-04”,“2013-07”,“2013-08”,“2013-10”,“2014-01”,“2015-01”

Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43