public final class MessageBuilder<T>
extends java.lang.Object
GenericMessage
,
ErrorMessage
Modifier and Type | Method and Description |
---|---|
Message<T> |
build() |
MessageBuilder<T> |
copyHeaders(java.util.Map<java.lang.String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
MessageBuilder<T> |
copyHeadersIfAbsent(java.util.Map<java.lang.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(java.lang.String headerName)
Remove the value for the given header name.
|
MessageBuilder<T> |
removeHeaders(java.lang.String... headerPatterns)
Removes all headers provided via array of 'headerPatterns'.
|
MessageBuilder<T> |
setErrorChannel(MessageChannel errorChannel) |
MessageBuilder<T> |
setErrorChannelName(java.lang.String errorChannelName) |
MessageBuilder<T> |
setHeader(java.lang.String headerName,
java.lang.Object headerValue)
Set the value for the given header name.
|
MessageBuilder<T> |
setHeaderIfAbsent(java.lang.String headerName,
java.lang.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(java.lang.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(java.lang.String headerName, java.lang.Object headerValue)
null
,
the header will be removed.public MessageBuilder<T> setHeaderIfAbsent(java.lang.String headerName, java.lang.Object headerValue)
public MessageBuilder<T> removeHeaders(java.lang.String... headerPatterns)
public MessageBuilder<T> removeHeader(java.lang.String headerName)
public MessageBuilder<T> copyHeaders(java.util.Map<java.lang.String,?> headersToCopy)
copyHeadersIfAbsent(Map)
to avoid overwriting
values. Note that the 'id' and 'timestamp' header values will never be overwritten.public MessageBuilder<T> copyHeadersIfAbsent(java.util.Map<java.lang.String,?> headersToCopy)
public MessageBuilder<T> setReplyChannel(MessageChannel replyChannel)
public MessageBuilder<T> setReplyChannelName(java.lang.String replyChannelName)
public MessageBuilder<T> setErrorChannel(MessageChannel errorChannel)
public MessageBuilder<T> setErrorChannelName(java.lang.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.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(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
)