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
FieldsModifier 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 Summary
ConstructorsModifierConstructorDescriptionMessageHeaders(@Nullable Map<String, Object> headers) Construct aMessageHeaderswith the given headers.protectedConstructor providing control over the ID and TIMESTAMP header values. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()boolean<T> @Nullable 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 interface 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
-
CONTENT_TYPE
-
REPLY_CHANNEL
-
ERROR_CHANNEL
-
-
Constructor Details
-
MessageHeaders
-
MessageHeaders
-
-
Method Details
-
getRawHeaders
-
getIdGenerator
-
getId
-
getTimestamp
-
getReplyChannel
-
getErrorChannel
-
get
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
entrySet
-
get
-
isEmpty
-
keySet
-
size
-
values
-
put
-
putAll
-
remove
-
clear
public void clear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException. -
equals
-
hashCode
-
toString
-