Message components

A message consists of the following distinct parts:

Message header fields

JRun provides support for JMS message header fields, sending these fields to all JMS message recipients. The following table describes the JMS message header fields supported by JRun:
Field
Contents
Set by
JMSDestination
Contains a Destination object for the message destination.
JRun
JMSDeliveryMode
Contains the delivery mode. Valid values are DeliveryMode.PERSISTENT and DeliveryMode.NON_PERSISTENT.
JRun
JMSMessageID
Contains a unique message ID.
JRun
JMSTimestamp
Contains the time that the message was sent to JRun.
JRun
JMSCorrelationID
Contains an application-specific string that links a response with its associated request.
JRun
JMSReplyTo
Contains a Destination object to which a reply should be sent. A reply is not required; however, the presence of a Destination object in this field implies that a reply is expected.
JRun
JMSRedelivered
Contains a Boolean indicating whether the message is being redelivered. If a consumer receives a message with JMSRedelivered set to true, the message was probably delivered previously, but the consumer did not acknowledge receipt.
JRun
JMSType
Contains a String specifying a message type.
Client
JMSExpiration
Contains a long specifying the message's expiration time. JRun sets this time by adding the time-to-live value specified by the client and the GMT at the time of the send.
JRun
JMSPriority
Contains the message's priority. Priorities are between 0 (lowest) and 9 (highest).
JRun
JMSXGroupID
Specifies an ID for grouping messages.
Client
JMSXGroupSeq
Specifies a sequence for grouping messages.
Client
JMSXRcvTimestamp
The time at which the message was delivered.
JRun

To access header fields, you use methods from the Message interface. The Message interface is extended by content-specific message interfaces, such as TextInterface and MapInterface.

Message properties

JRun does not support the optional JMSX-prefixed message properties defined in the JMS specification. However, you can use Message object methods to get and set properties. For example, you might use the following code snippet to set a property before sending a message:

...
try {
  // Set a property for user ID, assumes thisUser String variable.
  if(message != null) {
    message.setStringProperty("UserID", thisUser);
    message.setText(text);
    // Send to the queue. The message will last for 5 minutes.
    sender.send(_message, delivery, priority, 5 * 60 * 1000);
  }else {
    // Assumes usage in a servlet or JSP page.
    out.println("<H1>Message was null</H1>"); 
  }
}
...

And you might use the following code snippet to retrieve a property upon receiving a message:

final TextMessage message = (TextMessage)(_receiver.receiveNoWait());
// Get all properties
Enumeration e = message.getPropertyNames();
if(!e.hasMoreElements()) {
  // Assumes usage in a servlet or JSP page.
  out.println("<h1>no properties</H1>"); 
} 
while(e.hasMoreElements()) {
  String prop = (String)e.nextElement();
  out.print("<p> " + prop);
  // Assumes that all properties are Strings.
  out.println(": " + message.getStringProperty(prop));
} 

Message body types

The JMS 1.0.2b specification describes a set of message body forms, each of which is defined by an interface that extends Message.

The following table describes JMS message body interfaces:
Interface
Description
Comment
StreamMessage
Contains a stream of Java primitive values.
Populate and read this type sequentially.
MapMessage
Contains a set of name-value pairs. The names must be String objects and the values must be Java primitive types.
Access these sequentially by enumerator, or randomly by name.
TextMessage
Contains a single String object.
Use this for text messages or messages containing data in XML format.
ObjectMessage
Contains a serializable Java object.
Use one of the JDK Collection classes.
BytesMessage
Contains a stream of uninterpreted bytes.
This body type is not typically used.

JMS programming, including usage techniques for message body interfaces, is explained in Chapter 16, "JMS Programming Techniques".

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/jrun/4/Programmers_Guide/introjms3.htm