Package org.springframework.messaging
Class MessageHeaders
java.lang.Object
org.springframework.messaging.MessageHeaders
- All Implemented Interfaces:
Serializable
,Map<String,
Object>
The headers for a
Message
.
IMPORTANT: This class is immutable. Any mutating operation such as
put(..)
, putAll(..)
and others will throw
UnsupportedOperationException
.
Subclasses do have access to the raw headers, however, via getRawHeaders()
.
One way to create message headers is to use the
MessageBuilder
:
MessageBuilder.withPayload("foo").setHeader("key1", "value1").setHeader("key2", "value2");A second option is to create
GenericMessage
passing a payload as Object
and headers as a java.util.Map
:
Map headers = new HashMap(); headers.put("key1", "value1"); headers.put("key2", "value2"); new GenericMessage("foo", headers);A third option is to use
MessageHeaderAccessor
or one of its subclasses to create specific categories of headers.- Since:
- 4.0
- Author:
- Arjen Poutsma, Mark Fisher, Gary Russell, Juergen Hoeller
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The key for the message content type.static final String
The key for the message error channel.static final String
The key for the Message ID.static final UUID
UUID for none.static final String
The key for the message reply channel.static final String
The key for the message timestamp. -
Constructor Summary
ModifierConstructorDescriptionMessageHeaders
(Map<String, Object> headers) Construct aMessageHeaders
with the given headers.protected
Constructor providing control over the ID and TIMESTAMP header values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
<T> T
getId()
protected static IdGenerator
int
hashCode()
boolean
isEmpty()
keySet()
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.void
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.int
size()
toString()
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
ID_VALUE_NONE
UUID for none. -
ID
The key for the Message ID. This is an automatically generated UUID and should never be explicitly set in the header map except in the case of Message deserialization where the serialized Message's generated UUID is being restored.- See Also:
-
TIMESTAMP
The key for the message timestamp.- See Also:
-
CONTENT_TYPE
The key for the message content type.- See Also:
-
REPLY_CHANNEL
The key for the message reply channel.- See Also:
-
ERROR_CHANNEL
The key for the message error channel.- See Also:
-
-
Constructor Details
-
MessageHeaders
Construct aMessageHeaders
with the given headers. AnID
andTIMESTAMP
headers will also be added, overriding any existing values.- Parameters:
headers
- a map with headers to add
-
MessageHeaders
protected MessageHeaders(@Nullable Map<String, Object> headers, @Nullable UUID id, @Nullable Long timestamp) Constructor providing control over the ID and TIMESTAMP header values.
-
-
Method Details
-
getRawHeaders
-
getIdGenerator
-
getId
-
getTimestamp
-
getReplyChannel
-
getErrorChannel
-
get
-
containsKey
- Specified by:
containsKey
in interfaceMap<String,
Object>
-
containsValue
- Specified by:
containsValue
in interfaceMap<String,
Object>
-
entrySet
-
get
-
isEmpty
public boolean isEmpty() -
keySet
-
size
public int size() -
values
-
put
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
. -
putAll
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
. -
remove
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
. -
clear
public void clear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
. -
equals
-
hashCode
public int hashCode() -
toString
-