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 SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe key for the message content type.static final StringThe key for the message error channel.static final StringThe key for the Message ID.static final UUIDUUID for none.static final StringThe key for the message reply channel.static final StringThe key for the message timestamp.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionMessageHeaders(Map<String, Object> headers) Construct aMessageHeaderswith the given headers.protectedConstructor providing control over the ID and TIMESTAMP header values.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()boolean<T> TgetId()protected static IdGeneratorinthashCode()booleanisEmpty()keySet()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.voidSince MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.intsize()toString()values()Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
ID_VALUE_NONEUUID for none.
- 
IDThe 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:
 
- 
TIMESTAMPThe key for the message timestamp.- See Also:
 
- 
CONTENT_TYPEThe key for the message content type.- See Also:
 
- 
REPLY_CHANNELThe key for the message reply channel.- See Also:
 
- 
ERROR_CHANNELThe key for the message error channel.- See Also:
 
 
- 
- 
Constructor Details- 
MessageHeadersConstruct aMessageHeaderswith the given headers. AnIDandTIMESTAMPheaders will also be added, overriding any existing values.- Parameters:
- headers- a map with headers to add
 
- 
MessageHeadersprotected 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:
- containsKeyin interface- Map<String,- Object> 
 
- 
containsValue- Specified by:
- containsValuein interface- Map<String,- Object> 
 
- 
entrySet
- 
get
- 
isEmptypublic boolean isEmpty()
- 
keySet
- 
sizepublic int size()
- 
values
- 
putSince MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
- 
putAllSince MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
- 
removeSince MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
- 
clearpublic void clear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
 
-