Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract jms text content

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? jms message sample

like image 376
Rad4 Avatar asked Dec 01 '17 00:12

Rad4


1 Answers

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.

like image 149
Muralidharan.rade Avatar answered Oct 21 '22 16:10

Muralidharan.rade