public 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> 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 builder for a new
Message instance with the provided payload. |
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.message
- the Message from which the payload and all headers will be copiedpublic static <T> MessageBuilder<T> withPayload(T payload)
Message
instance with the provided payload.payload
- the payload for the new messagepublic MessageBuilder<T> setHeaders(MessageHeaderAccessor accessor)
MessageHeaderAccessor
.accessor
- the headers to usepublic MessageBuilder<T> setHeader(String headerName, 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(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(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)