Java Reference
In-Depth Information
A good analogy for JMS messages is mailing envelopes. Let's see how this analogy fits.
Message headers
Headers are name-value pairs common to all messages. In the envelope analogy, the mes-
sage header is the standard information found on the typical postal letter: the to and from
addresses, postage, and postmark. For example, the JMS message version of a mail post-
mark is the
JMSTimestamp
header. MOM sets this header to the current time when the
message is sent.
Here are some other commonly used JMS headers:
•
JMSCorrelationID
•
JMSReplyTo
•
JMSMessageID
Message properties
Message properties are similar to headers but are explicitly created by the application in-
stead of being standard across messages. Continuing with the envelope analogy, if you de-
cide to write “Happy Holidays” on the envelope to let the receiver know the envelope con-
tains a gift or a note, the text is a property instead of a header. In the ActionBazaar example,
one way to mark a shipping request as “Fragile” would be to add a
boolean
property
Fragile
and set it to
true
:
Message.setBooleanProperty("Fragile", true);
A property can be a
boolean
,
byte
,
double
,
float
,
int
,
long
,
short
,
String
,
or
Object
.
Message body
The message body contains the contents of the envelope; it's the payload of the message.
What you're trying to send in the body determines what message type you should use.
ShippingRequest
Java object. Alternatively, you could have chosen to send
BytesMessage
,
MapMessage
,
StreamMessage
, or
TextMessage
. Each of these
message types has a slightly different interface and usage pattern. There are no hard-and-