A message object is divided into three parts: Headers, Properties, and Payload ). For StreamMessage and
MapMessage, the message itself has a specific structure, while TextMessage, ObjectMessage, and BytesMessage are unstructured. A message can contain some important data or only notifications of an event.
The Headers section of a message usually contains some message descriptions, which are standard descriptions. Contains the following values:
JMSDestination
The destination, Topic, or Queue of the message.
JMSDeliveryMode
Message sending mode: persistent or nonpersistent. The former indicates that a message exists after it is restarted if the JMS provider is DOWN before it is consumed. In this case, the message will be lost. You can set it in the following way:
Producer. setDeliveryMode (DeliveryMode. NON_PERSISTENT );
JMSTimestamp
When the send () method is called, JMSTimestamp is automatically set as the current event. You can obtain this value using the following method:
Long timestamp = message. getJMSTimestamp ();
JMSExpiration
Indicates the validity period of a message. The message consumer can consume the message only within the validity period. The default value is 0, indicating that the message never expires. You can set it in the following way:
Producer. settimetolive (3600000); // valid for 1 hour (1000 ms * 60 seconds *
60 points)
Jmspriority
The priority of the message. 0-4 is the normal priority, and 5-9 is the high priority. You can set it as follows:
Producer. setpriority (9 );
Jmsmessageid
A string uniquely identifies a message.
Jmsreplyto
Sometimes the message producer wants the consumer to reply to a message, and JMSReplyTo is a Destination, indicating the Destination to be replied. Of course, the consumer can ignore it.
JMSCorrelationID
It is usually used to associate multiple messages. For example, to reply to a message, you can set JMSCorrelationID to the JMSMessageID of the received message.
JMSType
Indicates the structure of the message body, which is related to the JMS provider.
JMSRedelivered
If the value is true, the message is resent. Because sometimes the consumer does not confirm that he has received the message or the JMS provider is not sure whether the consumer has received the message.
In addition to the Header, message senders can add Properties ). These attributes can be application-defined attributes, JMS-defined attributes, and JMS-provider-defined attributes. Generally, we only apply custom attributes.
The usage of these headers and attributes will be discussed later.