Package io.awspring.cloud.sqs
Class MessageHeaderUtils
java.lang.Object
io.awspring.cloud.sqs.MessageHeaderUtils
Utility class for extracting
MessageHeaders from a Message.- Since:
- 3.0
- Author:
- Tomaz Fernandes
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Message<T>addHeaderIfAbsent(Message<T> message, String headerName, Object headerValue) Add a header to aMessagewhile preserving the id and timestamp.static MessageHeadersaddHeaderIfAbsent(MessageHeaders headers, String headerName, Object headerValue) static <T> Message<T>addHeadersIfAbsent(Message<T> message, Map<String, Object> newHeaders) Add headers to aMessagewhile preserving the id and timestamp.static MessageHeadersaddHeadersIfAbsent(MessageHeaders headers, Map<String, Object> newHeaders) 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.static <T> TGet the specified header or throw an exception if such header is not present.static StringgetHeaderAsString(Message<?> message, String headerName) Get the provided header asStringor throw if not present.static <T> StringgetId(Collection<Message<T>> messages) Return the messages' ID as a concatenated {@link String].static StringReturn the message's ID as {@link String].
-
Method Details
-
getId
Return the message's ID as {@link String].- Parameters:
message- the message.- Returns:
- the ID.
-
getId
Return the messages' ID as a concatenated {@link String].- Parameters:
messages- the messages.- Returns:
- the IDs.
-
getHeader
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
Get the provided header asStringor 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 aMessagewhile 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
Add headers to aMessagewhile 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)
-