The JMS API defines the standard form of a JMS message, which should be portable across all JMS providers. Because the JMS API was designed to accommodate many existing providers, the resulting message form encompasses a wide variety of features. Dynamo supports all of these features, but internally adheres to conventions that greatly narrow the set of features developers must master.

A JMS message consists of two parts, the header and the body. The header contains system-level information common to all messages, such as the destination, the time it was sent, etc., while the body contains only application-specific data. The header can also contain some application-specific information, stored as keyword/value properties. However, not all providers allow an arbitrary amount of data to be stored in the header, it’s a good idea to keep most application-specific data in the message body.

The most important header value is the JMSType. This is a String that is used to identify what kind of message is being sent. Handlers will often examine the JMSType to see how they should handle an incoming message.

The header is useful for specifying message selectors. When a receiver subscribes to a destination, it may specify a message selector, which acts as a filter for weeding out messages the receiver doesn’t want to see. The message selector must be specified in terms of the message’s header. For example, a receiver can specify a message selector saying that it wants to see only messages whose JMSType is atg.das.Startup. The message selector may refer to both system-level and application-specific header properties.

To accommodate the various data formats of existing providers, JMS defines five distinct message body types. In the JMS API, these translate into five Java interfaces, each subclassing javax.jms.Message:

javax.jms.TextMessage

The body of this message is a block of text, represented in Java as a String. For example, this type of message could be used to represent a message as an XML file.

javax.jms.ObjectMessage

The body of this message is a Java object (which must be serializable). For example, the message could contain a Java Bean whose properties represent the different data elements of the message.

javax.jms.MapMessage

The body of this message is set of keyword/value pairs.

javax.jms.BytesMessage

The body of this message is a block of binary data, represented in Java as a byte array. This format is often used to interface with an external messaging system that defines its own binary protocol for message formats.

javax.jms.StreamMessage

The body of this message is a list of Java primitive values. This type can be used to represent certain data types used by existing messaging systems.

JMS systems may support all, or only a subset, of these message formats. Dynamo’s JMS providers support the subset described in the next section.

 
loading table of contents...