Search code examples
javaspringjmsibm-mq

Why am I recieving a JMSBytesMessage when I'm sending an OBject message using Spring and MQ Queue


So I'm sending an object using Spring and IBM MQ Queue:

public void sendObjectMessage(final Object message) {

//  jmsTemplate.convertAndSend(message);

    jmsTemplate.send(new MessageCreator()
      {
        public Message createMessage(Session session) throws JMSException
        {
        ObjectMessage outMessage = session.createObjectMessage((Serializable) message);
        return(outMessage);
        }
      }); 
}

And during debugging I can see that I am indeed sending it as an object message. But using Spring's listener implementation I am picking up the messages in the onMessage() method as JMSBytesMessages????

public void onMessage(Message message) {
    System.out.println(">>>>>>> Recieved in onMessage");
    System.out.println(message.getClass());
}

OUTPUT:

>>>>>>> Recieved in onMessage
class com.ibm.jms.JMSBytesMessage

Anybody know whats going on here? This is difficult to debug as it seems to be happening on the queue???

Thanks for your help

P.S I've also tried to catch the message using

if (message instanceof ObjectMessage) {
    object = ((ObjectMessage) message).getObject();
}

and

if (message instanceof JMSBytesMessage) {
    System.out.println("ITS A BYTES MESSAGE!!!!!!!!!!!"); 
}

Neither of which work???


Solution

  • My first guess is, that you're using WebSphere AppServer and your JMS queue object (in JNDI) is configured to be a native MQ series client, i.e. you create a JMSObjectMessage which you hand over to the session and then MQSeries thinks it has to convert to BytesMessage.