2. The Core API

2.1 Message

The Spring Integration Message is a generic container for data. Any object can be provided as the payload, and each Message also includes a header containing user-extensible properties as key-value pairs. Here is the definition of the Message interface:

public interface Message<T> {
    Object getId();
    MessageHeader getHeader();
    T getPayload();
}

And the header provides the following properties:

Table 2.1. Properties of the MessageHeader

Property NameProperty Type
timestampjava.util.Date
expirationjava.util.Date
correlationIdjava.lang.Object
replyChannelNamejava.lang.String
sequenceNumberint
sequenceSizeint
propertiesjava.util.Properties
attributesMap<String,Object>


The base implementation of the Message interface is GenericMessage<T>, and it provides two constructors:

new GenericMessage<T>(Object id, T payload);
new GenericMessage<T>(T payload);

When no id is provided, a random unique id will be generated. There are also two convenient subclasses available currently: StringMessage and ErrorMessage. The latter accepts any Throwable object as its payload.

The Message is obviously a very important part of the API. By encapsulating the data in a generic wrapper, the messaging system can pass it around without any knowledge of the data's type. As the system evolves to support new types, or when the types themselves are modified and/or extended, the messaging system will not be affected by such changes. On the other hand, when some component in the messaging system does require access to information about the Message, such metadata can typically be stored to and retrieved from the metadata in the header (the 'properties' and 'attributes').