2016-12-01 160 views
0

從隊列接收消息時的NPE。 (僅當消息存在於隊列中時)。我覺得在反序列化消息時存在一個問題。從Azure服務總線接收消息時的NPE隊列

顯示java.lang.NullPointerException 在com.sun.jersey.api.client.ClientResponse.getResponseDate(ClientResponse.java:738) 在com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveMessage( ServiceBusRestProxy.java:288) 在com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveQueueMessage(ServiceBusRestProxy.java:225) 在com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor.receiveQueueMessage(ServiceBusExceptionProcessor。 java:142)

RECEIVE_AND_DELETE選項d輸入消息並拋出NPE。

所有其他操作,如創建隊列,發送消息等工作正常。有這個想法嗎?

代碼收到消息

public void receiveMessage(String queueName) { 
     try { 
      ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT; 
      opts.setReceiveMode(ReceiveMode.PEEK_LOCK); 

      while (true) { 
       ReceiveQueueMessageResult resultQM 
         = service.receiveQueueMessage(queueName, opts); 
       BrokeredMessage message = resultQM.getValue(); 
       if (message != null && message.getMessageId() != null) { 
        log.println("MessageID: " + message.getMessageId()); 
        // Display the queue message. 
        log.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); 
        } 
        log.println(""); 
        log.println("Custom Property: " 
          + message.getProperty("MyProperty")); 
        // Remove message from queue. 
        log.println("Deleting this message."); 
        //service.deleteMessage(message); 
       } else { 
        log.println("Finishing up - no more messages."); 
        break; 
        // Added to handle no more messages. 
        // Could instead wait for more messages to be added. 
       } 
      } 
     } catch (Exception e) { 
      log.print(e); 
     } 
    } 

回答

0

即使它被扔NPE的實際問題是與丟失的jar文件。這裏是jar文件列表

  <dependencies> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-compute</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-network</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-sql</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-storage</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-websites</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-svc-mgmt-media</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-servicebus</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
       <dependency> 
         <groupId>com.microsoft.azure</groupId> 
         <artifactId>azure-serviceruntime</artifactId> 
         <version>0.9.7</version> 
       </dependency> 
     </dependencies> 
相關問題