1
votes

I am using camel to send message to an IBM MQQueue. The MDB listening to this queue expects messages of the type com.ibm.jms.JMSMapMessage.

When I use camel producerTemplate, an exception is thrown. I am doing this producerTemplate.sendBody("wmq:queue",hashMap);

Exception data: java.lang.ClassCastException: com.ibm.jms.JMSMapMessage incompatible with javax.jms.ObjectMessage

So I tried Spring jmsTemplate, and it worked.

jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session)
                    throws JMSException {
                return session.createObjectMessage((Serializable) sctHmap);
            }
        });

Question: The jms component documentation says

It uses Spring's JMS support for declarative transactions, including Spring's JmsTemplate for sending and a MessageListenerContainer for consuming.

I tried with disabling camels auto conversion using mapJmsMessage=false. I realised it would not help as it would have sent a hash map, I still got the same exception. Is there any way I can get the producerTemplate to work in the same way as JMSTemplate? ProducerTemplate seems to be more elegant, atleast in terms of my unit tests

1
just serialize your hashmap to json and then send it as body. It can then be converted to any type - pvpkiran
What version of Camel do you use? And you can try setting ?jmsMessageType=Map as paramter to the endpoint uri in the camel producer template. - Claus Ibsen
And just to be sure the hashMap instance you send as the message body is a java.util.Map instance? - Claus Ibsen
i am using 2.20.1, i explicitly set the jmsMessagetype=Map, first as an option and second in the header. To do the latter I created a route, from("direct:start").setHeader().to(wmq) and used the producerTemplate to sendBody to this route - pointerness

1 Answers

1
votes

It seems I misinterpreted the classcast exception message. Camel was correctly sending, com.ibm.jms.JMSMapMessage, the MDB at the consumer application was expecting javax.jms.ObjectMessage. I resolved it by setting jmsMessageType=object in the endpoint URI. :)