javax.jms.Message from IBM MQ has "null" JMSDestination

227 views Asked by At

When consuming a javax.jms.Message from IBM MQ I want to log the message id and destination it came from like this:

Received [ID:...] from [...]

For some messages this works fine and looks like this:

Received [ID:414d5120465030303030374920202020a948b66401d61440] from [queue://MYQMGR/MYQ] 

But for some other queues on the same queue manager Message.getJMSDestination() returns null, and I get this:

Received [ID:414d512053415a324d5131452020202063c3b3fc9c229718] from [null]
  • What is the reason for this?
  • What can I do to fix it?

Details about my context:

  • JEE7, Java 8
  • MDB listens to MQ queue (onMessage(javax.jms.Message))
1

There are 1 answers

1
chughts On

I guess that you are using logic akin to

        try {
            Destination jmsDestination = message.getJMSDestination();
            if (jmsDestination != null) {
                q = ((Queue) jmsDestination).getQueueName();
                System.out.println(formatTime() + " JMS message received by from queue: " + q);
            } else {
                System.out.println(formatTime() + " MQ message received");
            }
        } catch (JMSRuntimeException | JMSException e) {
            msgErr = " ERROR: JMS error getting destination: " + e.getLocalizedMessage();
            throw new RuntimeException(msgErr, e);
        }

In which case a null destination indicates that the message didn't come from a JMS application. IE. if the sender application was a Node.js making use of the MQI API then you would expect to see JMSDestination as null.