org.springframework.messaging

## Class MessageHeaders

- java.lang.Object
- - org.springframework.messaging.MessageHeaders

- All Implemented Interfaces:
    Serializable, Map<String,Object>

      public final class MessageHeaders
      extends Object
      implements Map<String,Object>, Serializable

  The headers for a `Message`

  IMPORTANT: This class is immutable. Any mutating operation such as `put(..)`, `putAll(..)` and others will throw `UnsupportedOperationException`.

  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 sub-classes to create specific categories of headers.
  Since:
    4.0
  Author:
    Arjen Poutsma, Mark Fisher, Gary Russell
  See Also:
    `MessageBuilder`, `MessageHeaderAccessor`, Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `CONTENT_TYPE`
    `static String` | `ERROR_CHANNEL`
    `static String` | `ID` The key for the Message ID.
    `static String` | `REPLY_CHANNEL`
    `static String` | `TIMESTAMP`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MessageHeaders(Map<String,Object> headers)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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 object)`
    `Object` | `get(Object key)`
    `<T> T` | `get(Object key, Class<T> type)`
    `Object` | `getErrorChannel()`
    `UUID` | `getId()`
    `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> t)` 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()`

    - ### 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

          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

      See Also:
        Constant Field Values

    - #### REPLY_CHANNEL

          public static final String REPLY_CHANNEL

      See Also:
        Constant Field Values

    - #### ERROR_CHANNEL

          public static final String ERROR_CHANNEL

      See Also:
        Constant Field Values

    - #### CONTENT_TYPE

          public static final String CONTENT_TYPE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### MessageHeaders

          public MessageHeaders(Map<String,Object> headers)

  - ### Method Detail

    - #### getId

          public UUID getId()

    - #### getTimestamp

          public Long getTimestamp()

    - #### getReplyChannel

          public Object getReplyChannel()

    - #### getErrorChannel

          public Object getErrorChannel()

    - #### get

          public <T> T get(Object key,
                           Class<T> type)

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `Map<String,Object>`
      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object object)

      Specified by:
        `equals` in interface `Map<String,Object>`
      Overrides:
        `equals` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### containsKey

          public boolean containsKey(Object key)

      Specified by:
        `containsKey` in interface `Map<String,Object>`

    - #### containsValue

          public boolean containsValue(Object value)

      Specified by:
        `containsValue` in interface `Map<String,Object>`

    - #### entrySet

          public Set<Map.Entry<String,Object>> entrySet()

      Specified by:
        `entrySet` in interface `Map<String,Object>`

    - #### get

          public Object get(Object key)

      Specified by:
        `get` in interface `Map<String,Object>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Map<String,Object>`

    - #### keySet

          public Set<String> keySet()

      Specified by:
        `keySet` in interface `Map<String,Object>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Map<String,Object>`

    - #### values

          public Collection<Object> values()

      Specified by:
        `values` in interface `Map<String,Object>`

    - #### put

          public Object put(String key,
                            Object value)

      Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
      Specified by:
        `put` in interface `Map<String,Object>`

    - #### putAll

          public void putAll(Map<? extends String,? extends Object> t)

      Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
      Specified by:
        `putAll` in interface `Map<String,Object>`

    - #### remove

          public Object remove(Object key)

      Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
      Specified by:
        `remove` in interface `Map<String,Object>`

    - #### clear

          public void clear()

      Since MessageHeaders are immutable, the call to this method will result in `UnsupportedOperationException`.
      Specified by:
        `clear` in interface `Map<String,Object>`