LibraryToggle FramesPrintFeedback

JMS Message Basics

Overview

Messages are the backbone of a messaging system. A messages is a self-contained autonomous entity that may be resent several times across many clients (and processes) throughout its life span. Each consumer along a message's route will examine it and, depending on its contents (both payload and headers), may execute some business logic, modify it, or create new messages to accomplish a communicated task.

Message anatomy

As shown in Anatomy of a JMS message, a JMS message consists of three components: headers, properties, and body.

Figure 3. Anatomy of a JMS message

Anatomy of a JMS message

Message body

The body component contains the payload, which can be textual or binary data, as specified by using one of the six supported Java message types: Message, TextMessage, MapMessage, BytesMessage, StreamMessage, and ObjectMessage.

Message headers and properties

Header and property components transmit metadata used by clients and by the broker. All of the complexity of JMS messages resides in these two components, which are logically the same, but differ in their semantics.

  • Headers

    The JMS API provides a standard list of JMS headers (identified by the JMS prefix) and methods to work with them. The producer's send()method automatically assigns a number of these headers to messages, while others are optionally set either by the producer or by the broker.

  • Properties

    Client applications can create used-defined properties based on Java primitive types. The JMS API also provides generic methods for working with these user-defined properties.

    Two other types of properties, JMS-defined properties (identified by JMSX prefix) are reserved by the JMS specification, and the vendor-specific properties (identified by the JMSActiveMQBroker prefix) are reserved by the broker.

For a list of supported headers and properties, see ActiveMQ in Action (Snyder, Bosanac, and Davies)

Message selectors

Message selectors enable clients to use message headers and properties as filters, fine tuning where particular messages are sent. They enable a consumer to specify which messages it wants to receive from a destination based on particular header or property values.

Comments powered by Disqus