【问题标题】:Getting the Queue name from within the MDB从 MDB 中获取队列名称
【发布时间】:2013-02-18 02:45:21
【问题描述】:

我有 2 个 Websphere 应用程序服务器(WAS)应用程序,一个发送消息,另一个读取和处理它。我需要在阅读应用程序中知道队列名称以进行下游处理。 我正在尝试使用以下代码获取队列名称(在阅读应用程序中)。但是我得到 NullPointerException 因为getJMSDestination 正在返回null

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

请注意,队列名称是通过发送应用程序中的目标对象设置的。 我在发送应用程序中是否缺少任何其他参数?

【问题讨论】:

  • 您需要您从中获取消息的队列的名称或发件人将其发送到的队列的名称(它们可能不同)
  • 我需要第二个 MDB 应用程序从中获取消息的队列的名称

标签: jms websphere


【解决方案1】:

消息的目的地应该存储在其JMSDestination 属性中,您可以尝试获取它而不是使用getJMSDestination()

【讨论】:

  • 我用过这样的东西:logger.info("Dest from property: "+ message.getObjectProperty(MQConstants.MQ_JMS_DESTINATION));但是返回null
  • 我正在使用 Websphere MQ 7.0
  • MQConstants.MQ_JMS_DESTINATIONJMSDestination,您可以尝试使用MQConstants.RFH2_JMS_DESTINATION 从RFH2 标头读取JMS 目标
  • 不幸的是,以下语句也返回了 null:logger.info("Dest from RFH : "+ message.getObjectProperty(MQConstants.RFH2_JMS_DESTINATION));
  • 对不起,我没有更多的想法,希望其他人能够提供帮助
【解决方案2】:

我使用 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 对象来公开类似的方法?

【讨论】:

  • 是的,WAS 确实有一个可以使用的 Queue 对象。我正在使用类似这样的 Queue queue = (Queue)message.getJMSDestination(); logger.info("队列ID:"+queue.getQueueName());但是队列对象为空。发送应用程序为何将目的地作为 null 传递的任何线索
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2014-08-14
  • 1970-01-01
  • 1970-01-01
  • 2016-08-02
  • 2013-11-07
相关资源
最近更新 更多