Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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???

like image 242
Michael W Avatar asked Dec 19 '25 22:12

Michael W


1 Answers

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.

like image 145
Chris Avatar answered Dec 22 '25 12:12

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!