Question

I am using camel with JMS. I have a route, which just puts the jaxb annoted java object on a mq. The java object doesn't implement serializable, it just has "serialVersionUID".

The issue is, the object gets converted to XML and the destination queue has a XML message of type MQSTR. Is this the default behavior? Should we rely on it to do this all the time? Please note we are not using any marshal or unmarshal from java dsl and if we remove the jaxb dependency from pom.xml, it doesn't get converted to xml.

My route is plain vanila like this.

from("someRoute")
 .setExchangePattern(ExchangePattern.InOnly)
 .doTry().processRef("processor")
  .inOnly("destinationQueue")
 .doCatch(Exception.class)
  .to("errorQueue");

The processor populates the jaxb class and sets it to body. My processor code is like this

JaxbClass message =  mapper.mapHL7ToXML(hl7Message);        
exchange.getIn().setBody(message) ;

I am currently using this as dependency in pom for jaxb.

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jaxb</artifactId>
    <version>2.10.3</version>
</dependency>
Was it helpful?

Solution

Read about JMS and what message types it supports. As your java object is not serializable it cannot use that, and then fallback to use text messages, which your object is converted to before sending.

You can tell Camel which JMS type you want with jmsMessageType option. http://camel.apache.org/jms

And there is a type converter in camel-jaxb that can convert java objects that has been JAXB annotated to XML, and thus what happens in your use-case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top