Package org.springframework.messaging
Class MessageHeaders
- java.lang.Object
- org.springframework.messaging.MessageHeaders
- All Implemented Interfaces:
Serializable,Map<String,Object>
public class MessageHeaders extends Object implements Map<String,Object>, Serializable
The headers for aMessage.IMPORTANT: This class is immutable. Any mutating operation such as
put(..),putAll(..)and others will throwUnsupportedOperationException.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 createGenericMessagepassing a payload asObjectand headers as ajava.util.Map:Map headers = new HashMap(); headers.put("key1", "value1"); headers.put("key2", "value2"); new GenericMessage("foo", headers);A third option is to useMessageHeaderAccessoror one of its subclasses to create specific categories of headers.- Since:
- 4.0
- Author:
- Arjen Poutsma, Mark Fisher, Gary Russell, Juergen Hoeller
- See Also:
MessageBuilder,MessageHeaderAccessor, Serialized Form
Field Summary
Fields Modifier and Type Field Description static StringCONTENT_TYPEThe key for the message content type.static StringERROR_CHANNELThe key for the message error channel.static StringIDThe key for the Message ID.static UUIDID_VALUE_NONEUUID for none.static StringREPLY_CHANNELThe key for the message reply channel.static StringTIMESTAMPThe key for the message timestamp.
Constructor Summary
Constructors Modifier Constructor Description MessageHeaders(Map<String,Object> headers)Construct aMessageHeaderswith the given headers.protectedMessageHeaders(Map<String,Object> headers, UUID id, Long timestamp)Constructor providing control over the ID and TIMESTAMP header values.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<String,Object>>entrySet()booleanequals(Object other)Objectget(Object key)<T> Tget(Object key, Class<T> type)ObjectgetErrorChannel()UUIDgetId()protected static IdGeneratorgetIdGenerator()protected Map<String,Object>getRawHeaders()ObjectgetReplyChannel()LonggetTimestamp()inthashCode()booleanisEmpty()Set<String>keySet()Objectput(String key, Object value)Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.voidputAll(Map<? extends String,? extends Object> map)Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.Objectremove(Object key)Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.intsize()StringtoString()Collection<Object>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 Detail
ID_VALUE_NONE
public static final UUID ID_VALUE_NONE
UUID for none.
ID
public static final String 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:
- Constant Field Values
TIMESTAMP
public static final String TIMESTAMP
The key for the message timestamp.- See Also:
- Constant Field Values
CONTENT_TYPE
public static final String CONTENT_TYPE
The key for the message content type.- See Also:
- Constant Field Values
REPLY_CHANNEL
public static final String REPLY_CHANNEL
The key for the message reply channel.- See Also:
- Constant Field Values
ERROR_CHANNEL
public static final String ERROR_CHANNEL
The key for the message error channel.- See Also:
- Constant Field Values
Constructor Detail
MessageHeaders
public MessageHeaders(@Nullable Map<String,Object> headers)
Construct aMessageHeaderswith the given headers. AnIDandTIMESTAMPheaders will also be added, overriding any existing values.- Parameters:
headers- a map with headers to add
Method Detail
getRawHeaders
protected Map<String,Object> getRawHeaders()
getIdGenerator
protected static IdGenerator getIdGenerator()
getTimestamp
@Nullable public Long getTimestamp()
getReplyChannel
@Nullable public Object getReplyChannel()
getErrorChannel
@Nullable public Object getErrorChannel()
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,Object>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,Object>
put
public Object put(String key, Object value)
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
putAll
public void putAll(Map<? extends String,? extends Object> map)
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException.
remove
public Object remove(Object key)
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.
hashCode
public int hashCode()