The Message interface is the base interface for all messages in JMS. A Message is composed of a set of predefined header fields, an optional set of application-specific properties, and a body containing the content of the message. A set and get method are provided for each header field supported by a JMS message.

Properties can be added to a message using the setXXXProperty() methods, and they can be read using the getXXXProperty() methods. If a property is written with a value of a given type, it needs to be read from the message according to the following table. If in invalid get method is used for a property, then a MessageFormatException is thrown:

if writ-        
ten as:booleanbyteshortintlongfloatdoubleString
can be         
read as:         
booleanX      X
byte XXXX  X
short  XXX  X
int   XX  X
long    X  X
float     XXX
double      XX

Properties with names prefixed by “JMSX” are reserved for use by the JMS standard.

public interface Message {
// Public Constants
   public static final int DEFAULT_DELIVERY_MODE;                // =2
   public static final int DEFAULT_PRIORITY;                     // =4
   public static final long DEFAULT_TIME_TO_LIVE;                // =0
                  // Property Accessor Methods (by property name)
   public abstract String getJMSCorrelationID(
        ) throws JMSException;  
   public abstract void setJMSCorrelationID(
        String correlationID) throws JMSException;  
   public abstract byte[] getJMSCorrelationIDAsBytes(
        ) throws JMSException;  
   public abstract void setJMSCorrelationIDAsBytes(
        byte[] correlationID ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.