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 Form| Modifier and Type | Field and 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.
|
| 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, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic static final UUID ID_VALUE_NONE
public static final String ID
public static final String TIMESTAMP
public static final String CONTENT_TYPE
public static final String REPLY_CHANNEL
public static final String ERROR_CHANNEL
public MessageHeaders(@Nullable 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 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.public boolean equals(Object other)
public int hashCode()