我在使用Spring和MQ队列发送对象消息时收到JMSBytes

我在使用Spring和MQ队列发送对象消息时收到JMSBytes

本文介绍了为什么我在使用Spring和MQ队列发送对象消息时收到JMSBytesMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用Spring和IBM 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);
        }
      });
}

在调试过程中,我可以看到确实将其作为目标消息发送.但是,使用Spring的侦听器实现,我正在将onMessage()方法中的消息作为JMSBytesMessages接收?

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());
}

输出:

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

感谢您的帮助

P.S我也尝试使用

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

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

两者都不起作用?

推荐答案

我的第一个猜测是,您正在使用WebSphere AppServer,并且您的JMS队列对象(在JNDI中)被配置为本地MQ系列客户端,即您创建一个JMSObjectMessage并将其移交给会话,然后MQSeries认为它必须转换为BytesMessage.

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.

这篇关于为什么我在使用Spring和MQ队列发送对象消息时收到JMSBytesMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:00