WebSphere Message Brokers
File: ac24862_
Writer: John Cooper

Reference topic

This build: July 31, 2007 21:19:37

JMS message types

JMS defines six message interface types; a base message type and five subtypes. The message types are defined according to the type of the message payload, where the payload is the body of a message that holds the content. JMS specifies only the interface and does not specify the implementation. This allows for vendor specific implementation and transportation of messages while using a common interface.

The following table describes the six message types:
Message type Description
Message The base class. This message type is used for event notification and does not have a payload.
BytesMessage The payload is stored as an array of bytes. This message type is useful for exchanging data in an application’s native format and when JMS is used as a transport between two systems, where the JMS client does not know the message payload type.
TextMessage Data is stored as a string. This message type is useful for exchanging simple text messages and for more complex character data, such as XML documents.
StreamMessage A Stream message is a sequence of primitive Java types. The message object keeps track of the order and the types of these primitives within the stream. Formal conversion rules apply; for example, an exception is thrown if a JMS application tries to read a double value as a short value. Refer to the Java Message Service Specification, version 1.1 for a full list of the conversion rules.
21ABCDEFGH32.345 is an example of a StreamMessage payload. It consists of the following three fields:
  • an Integer, 21
  • a String, ABCDEFGH
  • a Float, 32.345

If the data structure is unknown, the generic method readObject() can be used to return the next object in the stream. If the structure of the data is known, the JMS client can be specific about the type of object being accessed.

MapMessage The payload of a MapMessage is stored as a set of name-value pairs. The name is defined as a string and the value is typed. The MapMessage is useful for delivering keyed data that can change from one message to the next.

NumberOfCopies:5 is an example of a MapMessage payload, where NumberOfCopies is the key and 5 is the value.

Data can be accessed by using getMapNames(), which returns a Java Enumeration object. It is possible to iterate through the MapMessage by using hasMoreElements() to retrieve the mapped name-value pairs.

ObjectMessage The Object message carries a serializable Java Object as its payload. It is useful for exchanging Java objects.
Related reference
JMS message structure
Representation of messages across the JMS Transport
JMS message as input
JMS message for output
JNDI administered objects
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:19:37

ac24862_ This topic's URL is: