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 createGenericMessage
passing a payload asObject
and 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 useMessageHeaderAccessor
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:
MessageBuilder
,MessageHeaderAccessor
, Serialized Form
Field Summary
Fields Modifier and Type Field Description static String
CONTENT_TYPE
The key for the message content type.static String
ERROR_CHANNEL
The key for the message error channel.static String
ID
The key for the Message ID.static UUID
ID_VALUE_NONE
UUID for none.static String
REPLY_CHANNEL
The key for the message reply channel.static String
TIMESTAMP
The key for the message timestamp.
Constructor Summary
Constructors Modifier Constructor Description MessageHeaders(Map<String,Object> headers)
Construct aMessageHeaders
with the given headers.protected
MessageHeaders(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 void
clear()
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<String,Object>>
entrySet()
boolean
equals(Object other)
Object
get(Object key)
<T> T
get(Object key, Class<T> type)
Object
getErrorChannel()
UUID
getId()
protected static IdGenerator
getIdGenerator()
protected Map<String,Object>
getRawHeaders()
Object
getReplyChannel()
Long
getTimestamp()
int
hashCode()
boolean
isEmpty()
Set<String>
keySet()
Object
put(String key, Object value)
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.void
putAll(Map<? extends String,? extends Object> map)
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.Object
remove(Object key)
Since MessageHeaders are immutable, the call to this method will result inUnsupportedOperationException
.int
size()
String
toString()
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 aMessageHeaders
with the given headers. AnID
andTIMESTAMP
headers 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:
containsKey
in interfaceMap<String,Object>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in 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()