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 aMessage
while preserving the id and timestamp.static MessageHeaders
addHeaderIfAbsent
(MessageHeaders headers, String headerName, Object headerValue) static <T> Message<T>
addHeadersIfAbsent
(Message<T> message, Map<String, Object> newHeaders) Add headers to aMessage
while preserving the id and timestamp.static MessageHeaders
addHeadersIfAbsent
(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> T
Get the specified header or throw an exception if such header is not present.static String
getHeaderAsString
(Message<?> message, String headerName) Get the provided header asString
or throw if not present.static <T> String
getId
(Collection<Message<T>> messages) Return the messages' ID as a concatenated {@link String].static String
Return 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 asString
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 aMessage
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
Add headers to aMessage
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)
-