Java Reference
In-Depth Information
TABLE 20-2. JMS Message Types
The JMS API provides methods for creating messages of each type and for filling in their
contents. For example, to create and send a TextMessage , you might use the following
statements:
Click here to view code image
TextMessage message = session.createTextMessage();
message.setText(msg_text);
// msg_text is a String
producer.send(message);
At the consuming end, a message arrives as a generic Message object and must be cast
to the appropriate message type. You can use one or more getter methods to extract the
message contents. The following code fragment uses the getText method:
Click here to view code image
Message m = consumer.receive();
if (m instanceof TextMessage) {
TextMessage message = (TextMessage) m;
System.out.println("Reading message: " + message.getText());
} else {
// Handle error
}
Search WWH ::




Custom Search