2013-03-04 132 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