我有2个Websphere应用服务器(WAS)应用程序,一个发送消息,另一个读取和处理它。我需要在读取应用程序中知道队列名称以进行下游处理。
我试图通过使用以下代码获取队列名称(在阅读应用程序中)。但是我得到NullPointerException,因为getJMSDestination
正在返回null
。
Queue queue = (Queue)message.getJMSDestination();
logger.info("Queue ID: "+queue.getQueueName());
请注意,队列名称是通过发送应用程序中的目标对象设置的。 是否还有其他参数在发送应用程序中设置?
答案 0 :(得分:2)
邮件应将目标存储在其JMSDestination
属性中,您可以尝试获取该目标,而不是使用getJMSDestination()
答案 1 :(得分: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 );
}
....
WAS是否有一个可以转换为类似方法的Queue对象?