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 approach allows for vendor-specific implementation and transportation of messages while using a common interface.
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 a format that is native to the application, and when JMS is used as a transport between two systems, where the JMS client does not know the message payload type. Use this message type to transmit XML messages to ensure that the message is transmitted efficiently, and is not subject to unnecessary data conversion. |
TextMessage | Data is stored as a string. This message type is useful for exchanging simple text messages. |
StreamMessage | A Stream message is a sequence of primitive Java™ types. The message object tracks
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
or 2.0 for a full list of the conversion rules.21ABCDEFGH32.345 is
an example of a StreamMessage payload. It consists of the
following three fields:
If the data structure is unknown, the generic
method |
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.
Data can be accessed
by using |
ObjectMessage | The Object message carries a serializable Java Object as its payload. It is useful for exchanging Java objects. |