类 MessageHeaders
- java.lang.Object
- org.springframework.messaging.MessageHeaders
- 所有已实现的接口:
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.- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Mark Fisher, Gary Russell, Juergen Hoeller
- 另请参阅:
MessageBuilder
,MessageHeaderAccessor
, 序列化表格
字段概要
字段 修饰符和类型 字段 说明 static String
CONTENT_TYPE
static String
ERROR_CHANNEL
static String
ID
The key for the Message ID.static UUID
ID_VALUE_NONE
static String
REPLY_CHANNEL
static String
TIMESTAMP
构造器概要
构造器 限定符 构造器 说明 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.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 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()
从接口继承的方法 java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
字段详细资料
ID_VALUE_NONE
public static final UUID ID_VALUE_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.- 另请参阅:
- 常量字段值
CONTENT_TYPE
public static final String CONTENT_TYPE
- 另请参阅:
- 常量字段值
REPLY_CHANNEL
public static final String REPLY_CHANNEL
- 另请参阅:
- 常量字段值
ERROR_CHANNEL
public static final String ERROR_CHANNEL
- 另请参阅:
- 常量字段值
构造器详细资料
MessageHeaders
public MessageHeaders(Map<String,Object> headers)
Construct aMessageHeaders
with the given headers. AnID
andTIMESTAMP
headers will also be added, overriding any existing values.- 参数:
headers
- a map with headers to add
方法详细资料
getRawHeaders
protected Map<String,Object> getRawHeaders()
getIdGenerator
protected static IdGenerator getIdGenerator()
getTimestamp
public Long getTimestamp()
getReplyChannel
public Object getReplyChannel()
getErrorChannel
public Object getErrorChannel()
containsKey
public boolean containsKey(Object key)
- 指定者:
containsKey
在接口中Map<String,Object>
containsValue
public boolean containsValue(Object value)
- 指定者:
containsValue
在接口中Map<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
.