[英]Connect Azure service bus on Android by Rest API
我正在编写一个Android应用程序并连接到Azure服务总线-主题。 我编写了代码以连接到现有的名称空间,例如本教程https://azure.microsoft.com/zh-cn/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);
但是它在ServiceBusContract service = ServiceBusService.create(config);处引发异常。 它说:“ java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.services.serviceBus.ServiceBusContract
我查找了某种方法来解决它,但还不行。所以我使用REST API连接了本教程的REST API蔚蓝
它可以运行并将消息发送到Azure Service Bus-主题。 现在,我想编写一种用于从该主题的订阅中获取消息的方法。 像这样使用Rest API
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");
但是它无法获取消息,responseString显示
"<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>"
我不知道为什么不支持它。 你能帮助我吗。 谢谢
根据您在Azure Java SDK中的代码,此问题是由使用不正确的namespace
sasKeyName
& sasKey
。 在参考文档中,作者创建了命名空间HowToSample
和SAS密钥SAS_key_value
,与您的命名空间不同。
因此,您需要用创建的服务总线的名称空间和SAS密钥值替换它们。 您可以在Azure门户或新门户上找到它们。
对于Service Bus REST API,请尝试在Peek-Lock Message
API的查询字符串中添加api-version
,请注意参考文档https://msdn.microsoft.com/zh-cn/library/中的内容azure / hh780771.aspx 。
版本和服务器概述
遵循Azure准则,REST API现在支持版本控制。 默认情况下,不传递任何版本表示当前服务行为。 现有REST API的任何更改都需要提供api版本值作为查询字符串。
版本 “ 2012-03”,“ 2012-08”,“ 2013-04”,“ 2013-07”,“ 2013-08”,“ 2013-10”,“ 2014-01”,“ 2015-01”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.