Java Reference
In-Depth Information
8-4. Interrogate Spring Integration Messages for Context
Information
Problem
You want more information about the message coming into the Spring Integration processing pipeline
than the type of the message implicitly can give you.
Solution
Interrogate the Spring Integration Message for header information specific to the message. These values
are enumerated as header values in a map (of type Map<String,Object> ).
How it Works
Using MessageHeaders for Fun and Profit
The Spring Integration Message interface is a generic wrapper that contains a pointer to the actual
payload of the message as well as to headers that provide contextual message metadata. You can
manipulate or augment this metadata to enable/enhance the functionality of components that are
downstream, too; for example, when sending a message through e-mail it's useful to specify the
TO / FROM headers.
Any time you expose a class to the framework to handle some requirement (such as the logic you
provide for the service-activator component or a transformer component), there will be some chance
to interact with the Message and with the message headers. Remember that Spring Integration pushes
a Message through a processing pipeline. Each component that interfaces with the Message has to act
on it or do something with it. One way of providing information to those components, and of getting
information about what's happened in the components up until that point, is to interrogate the
MessageHeaders .
There are several values that you should be aware of when working with Spring Integration (see
Table 8-1). These constants are exposed on the org.springframework.integration.core.MessageHeaders
interface.
Table 8-1. Common Headers Found in Spring Integration Messages
Constant
Description
ID
This is a unique value assigned to the message by the Spring Integration engine.
TIMESTAMP
Timestamp assigned to the message.
CORRELATION_ID
This is optional. It is used by some components (such as aggregators) to group
messages together in some sort of processing pipeline.
REPLY_CHANNEL
The String name of the channel to which the output of the current component
should be sent. This can be overridden.
Continued
 
Search WWH ::




Custom Search