Why am I recieving a JMSBytesMessage when I'm

2019-07-15 14:05发布

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

2条回答
仙女界的扛把子
2楼-- · 2019-07-15 14:31

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>
查看更多
beautiful°
3楼-- · 2019-07-15 14:32

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.

查看更多
登录 后发表回答