Class MessageBuilder<T>
java.lang.Object
org.springframework.messaging.support.MessageBuilder<T>
- Type Parameters:
T
- the message payload type
- Since:
- 4.0
- Author:
- Arjen Poutsma, Mark Fisher, Rossen Stoyanchev, Sam Brannen
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
copyHeaders
(Map<String, ?> headersToCopy) Copy the name-value pairs from the provided Map.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 andMessageHeaders
.static <T> MessageBuilder<T>
fromMessage
(Message<T> message) Create a builder for a newMessage
instance pre-populated with all the headers copied from the provided message.removeHeader
(String headerName) Remove the value for the given header name.removeHeaders
(String... headerPatterns) Removes all headers provided via array of 'headerPatterns'.setErrorChannel
(MessageChannel errorChannel) setErrorChannelName
(String errorChannelName) Set the value for the given header name.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.setHeaders
(MessageHeaderAccessor accessor) Set the message headers to use by providing aMessageHeaderAccessor
.setReplyChannel
(MessageChannel replyChannel) setReplyChannelName
(String replyChannelName) static <T> MessageBuilder<T>
withPayload
(T payload) Create a new builder for a message with the given payload.
-
Method Details
-
setHeaders
Set the message headers to use by providing aMessageHeaderAccessor
.- Parameters:
accessor
- the headers to use
-
setHeader
Set the value for the given header name. If the provided value isnull
, the header will be removed. -
setHeaderIfAbsent
Set the value for the given header name only if the header name is not already associated with a value. -
removeHeaders
Removes all headers provided via array of 'headerPatterns'. As the name suggests the array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy". -
removeHeader
Remove the value for the given header name. -
copyHeaders
Copy the name-value pairs from the provided Map. This operation will overwrite any existing values. UsecopyHeadersIfAbsent(Map)
to avoid overwriting values. Note that the 'id' and 'timestamp' header values will never be overwritten. -
copyHeadersIfAbsent
Copy the name-value pairs from the provided Map. This operation will not overwrite any existing values. -
setReplyChannel
-
setReplyChannelName
-
setErrorChannel
-
setErrorChannelName
-
build
-
fromMessage
Create a builder for a newMessage
instance pre-populated with all 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
, theoriginalMessage
it contains, will be passed on to new instance.- Parameters:
message
- the Message from which the payload and all headers will be copied
-
withPayload
Create a new builder for a message with the given payload.- Parameters:
payload
- the payload
-
createMessage
A shortcut factory method for creating a message with the given payload andMessageHeaders
.Note: the given
MessageHeaders
instance is used directly in the new message, i.e. it is not copied.- Parameters:
payload
- the payload to use (nevernull
)messageHeaders
- the headers to use (nevernull
)- Returns:
- the created message
- Since:
- 4.1
-