public class MessageHeaders extends Object implements Map<String,Object>, Serializable
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.MessageBuilder
,
MessageHeaderAccessor
,
Serialized FormModifier and Type | Field and Description |
---|---|
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 |
Modifier | Constructor and Description |
---|---|
|
MessageHeaders(Map<String,Object> headers)
Construct a
MessageHeaders with the given headers. |
protected |
MessageHeaders(Map<String,Object> headers,
UUID id,
Long timestamp)
Constructor providing control over the ID and TIMESTAMP header values.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
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 in
UnsupportedOperationException . |
void |
putAll(Map<? extends String,? extends Object> map)
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
Object |
remove(Object key)
Since MessageHeaders are immutable, the call to this method
will result in
UnsupportedOperationException . |
int |
size() |
String |
toString() |
Collection<Object> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final UUID ID_VALUE_NONE
public static final String ID
public static final String TIMESTAMP
public static final String REPLY_CHANNEL
public static final String ERROR_CHANNEL
public static final String CONTENT_TYPE
public MessageHeaders(Map<String,Object> headers)
MessageHeaders
with the given headers. An ID
and
TIMESTAMP
headers will also be added, overriding any existing values.headers
- a map with headers to addprotected static IdGenerator getIdGenerator()
public UUID getId()
public Long getTimestamp()
public Object getReplyChannel()
public Object getErrorChannel()
public boolean equals(Object other)
public int hashCode()
public boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
public boolean containsValue(Object value)
containsValue
in interface Map<String,Object>
public Object put(String key, Object value)
UnsupportedOperationException
.public void putAll(Map<? extends String,? extends Object> map)
UnsupportedOperationException
.public Object remove(Object key)
UnsupportedOperationException
.public void clear()
UnsupportedOperationException
.