How to prevent Camel from attempting to deserialize an ObjectMessage?

Solution Verified - Updated -

Environment

  • Fuse Mediation Router 2.x

Issue

  • How to prevent Camel from attempting to deserialize an ObjectMessage?

  • When routing Object messages from one JMS queue to another Camel appears to require that the class is present in the classpath.

  • Does Camel require that any class sent as an ObjectMessage be on the classpath?

Resolution

Normally when Camel receives a JMS message in a route it will try and convert that JMSMessage to the actual type such as a TextMessage, ObjectMessage, ByteMessage, etc. However in the case of an ObjectMessage Camel may need to have the class that the ObjectMessage contains on the classpath as Camel will try and deserialize it so that the object can be set as the body on the incoming message.

To avoid this the mapJmsMessage setting was added. It will prevent Camel from trying to cast the JMSMessage to the derived type. So for example:

from("jms:queue:myQueue?mapJmsMessage=false").
to("jms:queue:destQueue");

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments