I want to extract only jms message text without headers and properties from jms message.
To extract JMS header :msg.getJMSCorrelationID()
;
To extract JMS properties:jmsMessage.getPropertyNames()
But how to get only the text value from the message?
In the below sample message I want to extract only "hello queue".Is there a java function to do this?
If the message body is a text message (Plain text or XML), it can be extracted like the following.
String msgBody = ((TextMessage) message).getText();
The JMS 2.0 API exposes the additional method <T> T getBody(Class<T> c)
in the Message
interface.
If your Message broker or the source is JMS 2.0 compliant, then we extract the message body in a much more clean way without object cast as follows.
String msgBody = message.getBody(String.class);
Check out the this post for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With