2013-03-04 100 views
0

我有2個Websphere應用程序服務器(WAS)應用程序,一個發送消息,另一個讀取並處理它。我需要在下游處理的閱讀應用程序中知道隊列名稱。 我想通過使用下面的代碼獲取隊列名稱(在閱讀應用程序中)。但是,由於getJMSDestination返回null,我得到NullPointerException。從MDB中獲取隊列名稱

Queue queue = (Queue)message.getJMSDestination(); 
logger.info("Queue ID: "+queue.getQueueName()); 

請注意,隊列名稱是通過發送應用程序中的目標對象設置的。 在發送應用程序中是否缺少其他任何參數?

+0

您需要獲取消息的隊列的名稱或發件人發送給它的隊列的名稱(它們可能不同) – 2013-03-04 16:11:53

+0

我需要隊列的名稱第二個MDB應用程序從 – ssdimmanuel 2013-03-05 02:49:16

回答

2

的消息應該存儲在其JMSDestination屬性的目的地,你可以嘗試獲取該而不使用getJMSDestination()

+0

我用這樣的東西:logger.info(「Dest from property:」+ message.getObjectProperty(MQConstants.MQ_JMS_DESTINATION));但返回null – ssdimmanuel 2013-03-06 04:49:14

+0

您正在使用MQ或SIB嗎? – 2013-03-06 05:32:50

+0

我正在使用Websphere MQ 7.0 – ssdimmanuel 2013-03-06 05:42:49

0

我使用Spring和ActiveMQ,這似乎爲我工作:

public void processMessage(Message msg) 
    { 
     // Get the queue name from the supplied Message. 
     String sourceQueueName = "UNKNOWN"; 
     try 
     { 
      ActiveMQDestination sourceQueue = (ActiveMQDestination) msg.getJMSDestination(); 
      sourceQueueName = sourceQueue.getPhysicalName(); 
     } 
     catch (JMSException e) 
     { 
      LOGGER.error("Cannot get JMSDestination from Message: " + msg, e); 
     } 
     .... 

是否有一個Queue對象,您可以將其暴露給類似的方法?

+0

是的,我們有一個可以使用的Queue對象。我正在使用像這樣的隊列隊列=(隊列)message.getJMSDestination(); logger.info(「Queue ID:」+ queue.getQueueName());但是,隊列對象爲空。任何線索爲什麼目標將被髮送應用程序傳遞爲null – ssdimmanuel 2013-03-06 04:39:10