How to use Message Headers
Beside their payload, JMS Messages also have a number of header fields for the message receiver. Some of them have be set by the message sender, while others are set by the JMS provider (they will be ignored if the sender sets those).
Field Name | Set by.. | Always set? | Description |
---|---|---|---|
JMSDestination | JMS | yes | Name of the Destination the message was sent to |
JMSDeliveryMode | JMS | yes | Defines DeliveryMode (more) |
JMSMessageID | JMS | yes | Unique message id (more) |
JMSTimestamp | JMS | yes | Time when message was sent by client |
JMSCorrelationID | Sender | no | Link from response message to request (more) |
JMSReplyTo | Sender | no | Destination to reply to (more) |
JMSRedelivered | JMS | yes | Signals that this message was already sent before (more) |
JMSType | Sender | no | Describes the type of message (more) |
JMSExpiration | JMS | no | Time at which message expires (more) |
JMSPriority | JMS | no | Priority 0 (lowest) - 9 (highest) (more) |
There are simple getters and setters for all header fields:
Message msg = ...
// Setting a header:
msg.setJMSPriority(9);
// Reading a header:
String msgId = msg.getJMSMessageID();