public final class MutableMessageBuilder<T> extends AbstractIntegrationMessageBuilder<T>
IMPORTANT: Mutable messages may share state (such as message headers); such messages should never be exposed to other components or undesirable side-effects may result.
It is generally recommended that messages transferred between components should always be immutable unless great care is taken with their use.
Modifier and Type | Method and Description |
---|---|
Message<T> |
build() |
AbstractIntegrationMessageBuilder<T> |
copyHeaders(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
AbstractIntegrationMessageBuilder<T> |
copyHeadersIfAbsent(Map<String,?> headersToCopy)
Copy the name-value pairs from the provided Map.
|
static <T> MutableMessageBuilder<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. |
protected Object |
getCorrelationId() |
<V> V |
getHeader(String key,
Class<V> type) |
Map<String,Object> |
getHeaders() |
T |
getPayload() |
protected List<List<Object>> |
getSequenceDetails() |
protected Object |
getSequenceNumber() |
protected Object |
getSequenceSize() |
AbstractIntegrationMessageBuilder<T> |
removeHeader(String headerName)
Remove the value for the given header name.
|
AbstractIntegrationMessageBuilder<T> |
removeHeaders(String... headerPatterns)
Removes all headers provided via array of 'headerPatterns'.
|
AbstractIntegrationMessageBuilder<T> |
setHeader(String headerName,
Object headerValue)
Set the value for the given header name.
|
AbstractIntegrationMessageBuilder<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.
|
static <T> MutableMessageBuilder<T> |
withPayload(T payload)
Create a builder for a new
Message instance with the provided payload. |
static <T> MutableMessageBuilder<T> |
withPayload(T payload,
boolean generateHeaders)
Create a builder for a new
Message instance with the provided payload. |
filterAndCopyHeadersIfAbsent, popSequenceDetails, pushSequenceDetails, setCorrelationId, setErrorChannel, setErrorChannelName, setExpirationDate, setExpirationDate, setPriority, setReplyChannel, setReplyChannelName, setSequenceNumber, setSequenceSize
public T getPayload()
getPayload
in class AbstractIntegrationMessageBuilder<T>
public Map<String,Object> getHeaders()
getHeaders
in class AbstractIntegrationMessageBuilder<T>
@Nullable public <V> V getHeader(String key, Class<V> type)
getHeader
in class AbstractIntegrationMessageBuilder<T>
public static <T> MutableMessageBuilder<T> withPayload(T payload)
Message
instance with the provided payload.T
- The type of the payload.payload
- the payload for the new messagepublic static <T> MutableMessageBuilder<T> withPayload(T payload, boolean generateHeaders)
Message
instance with the provided payload.
The generateHeaders
flag allows to disable MessageHeaders.ID
and MessageHeaders.TIMESTAMP
headers generation.T
- The type of the payload.payload
- the payload for the new messagegenerateHeaders
- whether generate MessageHeaders.ID
and MessageHeaders.TIMESTAMP
headerspublic static <T> MutableMessageBuilder<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.T
- The type of the payload.message
- the Message from which the payload and all headers will be copiedpublic AbstractIntegrationMessageBuilder<T> setHeader(String headerName, @Nullable Object headerValue)
AbstractIntegrationMessageBuilder
null
, the header will be removed.setHeader
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.headerValue
- The header value.public AbstractIntegrationMessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue)
AbstractIntegrationMessageBuilder
setHeaderIfAbsent
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.headerValue
- The header value.public AbstractIntegrationMessageBuilder<T> removeHeaders(String... headerPatterns)
AbstractIntegrationMessageBuilder
removeHeaders
in class AbstractIntegrationMessageBuilder<T>
headerPatterns
- The header patterns.public AbstractIntegrationMessageBuilder<T> removeHeader(String headerName)
AbstractIntegrationMessageBuilder
removeHeader
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.public AbstractIntegrationMessageBuilder<T> copyHeaders(@Nullable Map<String,?> headersToCopy)
AbstractIntegrationMessageBuilder
AbstractIntegrationMessageBuilder.copyHeadersIfAbsent(Map)
to avoid overwriting values. Note that the 'id' and 'timestamp' header values
will never be overwritten.copyHeaders
in class AbstractIntegrationMessageBuilder<T>
headersToCopy
- The headers to copy.MessageHeaders.ID
,
MessageHeaders.TIMESTAMP
public AbstractIntegrationMessageBuilder<T> copyHeadersIfAbsent(@Nullable Map<String,?> headersToCopy)
AbstractIntegrationMessageBuilder
copyHeadersIfAbsent
in class AbstractIntegrationMessageBuilder<T>
headersToCopy
- The headers to copy.protected List<List<Object>> getSequenceDetails()
getSequenceDetails
in class AbstractIntegrationMessageBuilder<T>
protected Object getCorrelationId()
getCorrelationId
in class AbstractIntegrationMessageBuilder<T>
protected Object getSequenceNumber()
getSequenceNumber
in class AbstractIntegrationMessageBuilder<T>
protected Object getSequenceSize()
getSequenceSize
in class AbstractIntegrationMessageBuilder<T>
public Message<T> build()
build
in class AbstractIntegrationMessageBuilder<T>