[英]CRM Dynamics Online 2016 Azure SDK for Java receive BrokeredMessages with 500 error code
I have a problem with CRM Dynamics Online 2016 Azure SDK for Java. 我在使用CRM Dynamics Online 2016 Azure SDK for Java时遇到问题。 I can connect to Azure Service Bus, I can see queues and message count in queues, but cannot receive messages. 我可以连接到Azure Service Bus,可以看到队列和队列中的消息计数,但是无法接收消息。 Message Id is null and message body contain 500 error 邮件ID为空,邮件正文包含500个错误
500
The server was unable to process the request;500
服务器无法处理请求; please retry the operation. 请重试该操作。 If the problem persists, please contact your Service Bus administrator and provide the tracking id. 如果问题仍然存在,请联系您的Service Bus管理员并提供跟踪ID。 TrackingId:acf8a543-33c9-486d-b13b-443823e6c394_G9,TimeStamp:4/13/2016 7:26:22 AM. TrackingId:acf8a543-33c9-486d-b13b-443823e6c394_G9,TimeStamp:4/13/2016 7:26:22 AM。 If the problem persists, please contact your Service Bus administrator and provide the tracking id. 如果问题仍然存在,请联系您的Service Bus管理员并提供跟踪ID。 TrackingId:acf8a543-33 TrackingId:acf8a543-33
Is there any working sample on the Internet to solve the problem? 互联网上是否有任何可行的示例可以解决该问题?
Test code: 测试代码:
@Test
public void readAllExistedMessagesFromAllQueue() {
try {
ServiceBusContract serviceBusContract = ServiceBusConfiguration.configureWithConnectionString(null, Configuration.load(), ASB_CONNECTION_STRING).create(ServiceBusContract.class);
ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
opts.setReceiveMode(ReceiveMode.PEEK_LOCK);
ListQueuesResult result = serviceBusContract.listQueues();
if (result != null && result.getItems().size() > 0) {
for (QueueInfo queueInfo : result.getItems()) {
logger.debug("queu: " + queueInfo.getPath() + " MessageCount: " + queueInfo.getMessageCount());
for (int i = 0; i < result.getItems().size(); i++) {
BrokeredMessage message = serviceBusContract.receiveQueueMessage(queueInfo.getPath(),
opts).getValue();
if (message == null) {
continue;
}
System.out.print("__________________________________________");
System.out.println("MessageID: " + message.getMessageId());
System.out.print("From queue: ");
byte[] b = new byte[200];
String s = null;
int numRead = message.getBody().read(b);
while (-1 != numRead) {
s = new String(b);
s = s.trim();
System.out.print(s);
numRead = message.getBody().read(b);
}
System.out.println();
}
}
}
} catch (IOException e) {
logger.error(e);
} catch (ServiceException e) {
logger.error(e);
}
}
Per my experience, according to the source code and javadocs of Service Bus, the ServiceBusContract
is a Java interface, that you can't directly create an instance of the interface ServiceBusContract
. 根据我的经验,根据Service Bus的源代码和javadocs , ServiceBusContract
是一个Java接口,您无法直接创建ServiceBusContract
接口的实例。
So please try to use the code below from the section Create a queue
of the document "How to use Service Bus queues". 因此,请尝试使用Create a queue
文档“如何使用服务总线队列” Create a queue
部分中的以下代码。
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
"<your-servicebus-namespace>",
"RootManageSharedAccessKey",
"<SAS-key-value>",
".servicebus.windows.net"
);
ServiceBusContract serviceBusContract = ServiceBusService.create(config);
Update 更新资料
You can find the SharedAccessKeyName
& SharedAccessKey
in the connection string via click the button below at the bottom of your service bus page. 通过单击服务总线页面底部下方的按钮,可以在连接字符串中找到SharedAccessKeyName
和SharedAccessKey
。
Then, show the view below and copy the CONNECTION STRING
. 然后,显示下面的视图并复制CONNECTION STRING
。
The connection string like this below. 连接字符串如下所示。
Endpoint=sb://<your-servicebus-namespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<SAS-key-value>
Please copy the correct part of connection string instead of the related part of the code. 请复制连接字符串的正确部分,而不是代码的相关部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.