Message Structure
Messages are composed of the following parts:
Header. All messages support the same set of header fields. Header fields contain predefined values that allow clients and providers to identify and route messages. Each of the fields supports its own
set and
get methods for managing data; some fields are set automatically by the
send and
publish methods, whereas others must be set by the client.
Examples of header fields include:
JMSDestination, which holds a
destination object representing the destination to which the message is to be sent.
JMSMessageID, which holds a unique message identifier value and is set automatically.
JMSCorrelationID, which is used to link a reply message with its requesting message. This value is set by the client application.
JMSReplyTo, which is set by the client and takes as a value a
Destination object representing where the reply is being sent. If no reply is being sent, this field is set to null.
Properties (optional). Properties are used to add optional fields to the message header. There are several types of message property fields.
Application-specific properties are typically used to hold message selector values. Message selectors are used to filter and route messages.
Standard properties. The API provides some predefined property names that a provider may support. Support for the
JMSXGroupID and
JMSXGroupSeq is required; however, support for all other standard properties is optional.
Provider-specific properties are unique to the messaging provider and typically refer to internal values.
Body (optional). JMS defines various types of message body formats that are compatible with most messaging styles. Each form is defined by a message interface:
StreamMessage. A message whose body contains a stream of Java primitive values. It is filled and read sequentially.
MapMessage. A message whose body contains a set of name-value pairs where names are Strings and values are Java primitive types. The entries can be accessed sequentially by enumerator or randomly by name. The order of the entries is undefined.
TextMessage. A message whose body contains a
java.lang.String. ObjectMessage. A message that contains a Serializable Java object.
BytesMessage. A message that contains a stream of uninterpreted bytes. This message type is for literally encoding a body to match an existing message format. In many cases, it will be possible to use one of the other, self-defining, message types instead.
Both StreamMessage and MapMessage support the same set of primitive data types. Conversions from one data type to another are possible.