When sending XML to JMS should I use TextMessage or BytesMessage When sending XML to JMS should I use TextMessage or BytesMessage xml xml

When sending XML to JMS should I use TextMessage or BytesMessage


I agree with jos' comment to your question. First off, you should choose the kind of message type that best expresses the semantics of your content. Reading the TextMessage Javadoc, I'd go for that:

This message type can be used to transport text-based messages, including those with XML content.

So if you do run into trouble with your text message encoding, then there's probably some mis-configuration on the client / server side. But that shouldn't be a motivation for abusing a different message type that was not primarily intended for text transfer, such as BytesMessage.

N.B: Even with BytesMessage, you can get the encoding wrong. Imagine:

// Send that data through JMSbyte[] data1 = "source text".getBytes("ISO-8859-1");// Receive the byte stream on the other side. OoopsString data2 = new String(data1, "UTF-8");