Class MessageHeaderUtils

java.lang.Object
io.awspring.cloud.sqs.MessageHeaderUtils

public class MessageHeaderUtils extends Object
Utility class for extracting MessageHeaders from a Message.
Since:
3.0
Author:
Tomaz Fernandes
  • Method Details

    • getId

      public static String getId(Message<?> message)
      Return the message's ID as {@link String].
      Parameters:
      message - the message.
      Returns:
      the ID.
    • getId

      public static <T> String getId(Collection<Message<T>> messages)
      Return the messages' ID as a concatenated {@link String].
      Parameters:
      messages - the messages.
      Returns:
      the IDs.
    • getHeader

      public static <T> T getHeader(Message<?> message, String headerName, Class<T> classToCast)
      Get the specified header or throw an exception if such header is not present.
      Type Parameters:
      T - the class type.
      Parameters:
      message - the message.
      headerName - the header name.
      classToCast - the class to which the header should be cast to.
      Returns:
      the header value.
    • getHeader

      public static <T, U> Collection<T> getHeader(Collection<Message<U>> messages, String headerName, Class<T> classToCast)
      Get the specified header or throw an exception if such header is not present.
      Type Parameters:
      T - the header class type.
      U - the messages payload class type.
      Parameters:
      messages - the messages.
      headerName - the header name.
      classToCast - the class to which the header should be cast to.
      Returns:
      the header value.
    • getHeaderAsString

      public static String getHeaderAsString(Message<?> message, String headerName)
      Get the provided header as String or throw if not present.
      Parameters:
      message - the message.
      headerName - the header name.
      Returns:
      the header value.
    • addHeaderIfAbsent

      public static <T> Message<T> addHeaderIfAbsent(Message<T> message, String headerName, Object headerValue)
      Add a header to a Message while preserving the id and timestamp. Note that since messages are immutable, a new instance will be returned.
      Type Parameters:
      T - the payload type.
      Parameters:
      message - the message to add headers to.
      headerName - the header name.
      headerValue - the header value.
      Returns:
      the new message.
    • addHeadersIfAbsent

      public static <T> Message<T> addHeadersIfAbsent(Message<T> message, Map<String,Object> newHeaders)
      Add headers to a Message while preserving the id and timestamp. Note that since messages are immutable, a new instance will be returned.
      Type Parameters:
      T - the payload type.
      Parameters:
      message - the message to add headers to.
      newHeaders - the headers to add.
      Returns:
      the new message.
    • addHeaderIfAbsent

      public static MessageHeaders addHeaderIfAbsent(MessageHeaders headers, String headerName, Object headerValue)
    • addHeadersIfAbsent

      public static MessageHeaders addHeadersIfAbsent(MessageHeaders headers, Map<String,Object> newHeaders)