我正在使用POC
处理使用azure作为平台从客户端到服务器的大数据。
在我的初始POC
结果中,我能够将数据发送到服务总线队列。
但问题是当我从服务总线队列中获取数据时。
我正在使用的技术堆栈如下: -
以下是我得到的错误: -
java.lang.NullPointerException
at com.sun.jersey.api.client.ClientResponse.getResponseDate(ClientResponse.java:669)
at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveMessage(ServiceBusRestProxy.java:277)
at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveQueueMessage(ServiceBusRestProxy.java:216)
at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor.receiveQueueMessage(ServiceBusExceptionProcessor.java:137)
at com.toyota.tme.services.impl.messageQueueImpl.getMessage(messageQueueImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:129)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:187)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:166)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1568)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:164)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1539)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:524)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:459)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:280)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(Thread.java:745)
243178483 [qtp670576685-43] INFO org.apache.cxf.interceptor.LoggingOutInterceptor - Outbound Message
我使用的代码如下: -
public Response getMessage() throws Exception {
ServiceBusConfig serviceBusConfig = new ServiceBusConfig();
ServiceBusContract serviceBusContract = serviceBusConfig.serviceBusContract();
LOGGER.info("serviceBusContract: " + serviceBusContract);
StringBuffer stringBuffer = new StringBuffer();
try {
ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
LOGGER.info("opts: " + opts);
opts.setReceiveMode(ReceiveMode.PEEK_LOCK);
LOGGER.info(" after opts: " + opts);
while (true) {
ReceiveQueueMessageResult resultQM =
serviceBusContract.receiveQueueMessage("dev1-queue", opts);
LOGGER.info("resultQM: " + resultQM);
BrokeredMessage message = resultQM.getValue();
LOGGER.info("message: " + message);
if (message != null && message.getMessageId() != null) {
LOGGER.info("MessageID: " + message.getMessageId());
// Display the queue message.
LOGGER.info("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();
LOGGER.info(s);
stringBuffer.append(s);
numRead = message.getBody().read(b);
}
} else {
LOGGER.info("Finishing up - no more messages.");
break;
// Added to handle no more messages.
// Could instead wait for more messages to be added.
}
}
} catch (ServiceException e) {
LOGGER.info("ServiceException encountered: ");
LOGGER.info(e.getMessage());
e.printStackTrace();
//System.exit(-1);
} catch (Exception e) {
LOGGER.info("Generic exception encountered: ");
LOGGER.info(e.getMessage());
e.printStackTrace();
//System.exit(-1);
}
}
答案 0 :(得分:0)
当一个人没有准备好时,它似乎试图收到一条消息。我不熟悉如何使用serviceBusContract异步侦听来自队列的消息。
我已经能够使用Apache Qpid JMS客户端库向Queue发送消息或从Queue接收消息。这是针对服务总线的Java消息传递的推荐方法。 Apache Qpid所做的是在Service Bus提供服务的AMQP端点上提供JMS层。我发现,对于队列,与Service Bus的交互与其他JMS提供者没什么不同。
我使用Spring-JMS(使用Spring引导......但JMS应该在普通的Spring中工作)和AMQP一起使用队列来处理消息。您可以在此处找到有关我如何执行此操作的更多具体细节
http://ramblingstechnical.blogspot.in/p/using-azure-service-bus-with-spring-jms.html