【发布时间】:2015-10-30 13:53:04
【问题描述】:
我对这个队列有一个奇怪的问题。当我使用它时,即使我在 Microsoft azure 网站上看到队列中有一个事件,它也不总是读取它。例如,4 次我得到消息为空,第 5 次消息是好的。它有效,但并非总是如此。我从这个网站了解到: https://azure.microsoft.com/pl-pl/documentation/articles/service-bus-java-how-to-use-queues/。
这是我的代码(几乎与网站上的相同)。我也是用Jackson来序列化的。:
Configuration config =
ServiceBusConfiguration.configureWithSASAuthentication(
engineConfiguration.getServiceBusNamespace(),
engineConfiguration.getServiceBusPolicyName(),
engineConfiguration.getServiceBusSasKeyValue(),
".servicebus.windows.net"
);
ServiceBusContract service = ServiceBusService.create(config);
try
{
ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
opts.setReceiveMode(ReceiveMode.PEEK_LOCK);
ReceiveQueueMessageResult resultQM =
service.receiveQueueMessage(engineConfiguration.getServiceBusQueueName(), opts);
Something somethingObject = mapper.readValue(resultQM.getValue().getBody(), Something.class);
service.deleteMessage(resultQM.getValue());
return somethingObject;
}
catch (ServiceException e) {
throw new RuntimeException(e);
}
catch (Exception e) {
throw new RuntimeException(e);
}
【问题讨论】:
标签: java azure queue message-queue servicebus