T
- the message payload typepublic final class MessageBuilder<T> extends Object
GenericMessage
,
ErrorMessage
Modifier and Type | Method and Description |
---|---|
Message<T> |
build() |
MessageBuilder<T> |
copyHeaders(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
MessageBuilder<T> |
copyHeadersIfAbsent(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
static <T> Message<T> |
createMessage(T payload,
MessageHeaders messageHeaders)
A shortcut factory method for creating a message with the given payload
and
MessageHeaders . |
static <T> MessageBuilder<T> |
fromMessage(Message<T> message)
Create a builder for a new
Message instance pre-populated with all of the
headers copied from the provided message. |
MessageBuilder<T> |
removeHeader(String headerName)
Remove the value for the given header name.
|
MessageBuilder<T> |
removeHeaders(String... headerPatterns)
Removes all headers provided via array of 'headerPatterns'.
|
MessageBuilder<T> |
setErrorChannel(MessageChannel errorChannel) |
MessageBuilder<T> |
setErrorChannelName(String errorChannelName) |
MessageBuilder<T> |
setHeader(String headerName,
Object headerValue)
Set the value for the given header name.
|
MessageBuilder<T> |
setHeaderIfAbsent(String headerName,
Object headerValue)
Set the value for the given header name only if the header name is not already
associated with a value.
|
MessageBuilder<T> |
setHeaders(MessageHeaderAccessor accessor)
Set the message headers to use by providing a
MessageHeaderAccessor . |
MessageBuilder<T> |
setReplyChannel(MessageChannel replyChannel) |
MessageBuilder<T> |
setReplyChannelName(String replyChannelName) |
static <T> MessageBuilder<T> |
withPayload(T payload)
Create a new builder for a message with the given payload.
|
public MessageBuilder<T> setHeaders(MessageHeaderAccessor accessor)
MessageHeaderAccessor
.accessor
- the headers to usepublic MessageBuilder<T> setHeader(String headerName, @Nullable Object headerValue)
null
,
the header will be removed.public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue)
public MessageBuilder<T> removeHeaders(String... headerPatterns)
public MessageBuilder<T> removeHeader(String headerName)
public MessageBuilder<T> copyHeaders(@Nullable Map<String,?> headersToCopy)
copyHeadersIfAbsent(Map)
to avoid overwriting
values. Note that the 'id' and 'timestamp' header values will never be overwritten.public MessageBuilder<T> copyHeadersIfAbsent(@Nullable Map<String,?> headersToCopy)
public MessageBuilder<T> setReplyChannel(MessageChannel replyChannel)
public MessageBuilder<T> setReplyChannelName(String replyChannelName)
public MessageBuilder<T> setErrorChannel(MessageChannel errorChannel)
public MessageBuilder<T> setErrorChannelName(String errorChannelName)
public static <T> MessageBuilder<T> fromMessage(Message<T> message)
Message
instance pre-populated with all of the
headers copied from the provided message. The payload of the provided Message will
also be used as the payload for the new message.
If the provided message is an ErrorMessage
, the
originalMessage
it contains, will be
passed on to new instance.
message
- the Message from which the payload and all headers will be copiedpublic static <T> MessageBuilder<T> withPayload(T payload)
payload
- the payloadpublic static <T> Message<T> createMessage(@Nullable T payload, MessageHeaders messageHeaders)
MessageHeaders
.
Note: the given MessageHeaders
instance is used
directly in the new message, i.e. it is not copied.
payload
- the payload to use (never null
)messageHeaders
- the headers to use (never null
)