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

倾然丶 夕夏残阳落幕 提交于 2020-01-24 09:26:41

问题


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


回答1:


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.




回答2:


I had the same problem. In my case, I was using the wrong transport type:

<bean id="mqQueue" class="com.ibm.mq.jms.MQQueue">
    <property name="baseQueueName" value="..." />
    <property name="targetClient">
        <util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_CLIENT_NONJMS_MQ" />
    </property>
</bean>

Instead it should have been:

<bean id="mqQueue" class="com.ibm.mq.jms.MQQueue">
    <property name="baseQueueName" value="..." />
    <property name="targetClient">
        <util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_CLIENT_JMS_COMPLIANT" />
    </property>
</bean>


来源:https://stackoverflow.com/questions/6150006/why-am-i-recieving-a-jmsbytesmessage-when-im-sending-an-object-message-using-sp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!