public final class MessageBuilder<T> extends AbstractIntegrationMessageBuilder<T>
GenericMessage
s.
Named MessageBuilder instead of DefaultMessageBuilder for backwards
compatibility.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. |
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() |
MessageBuilder<T> |
popSequenceDetails() |
MessageBuilder<T> |
pushSequenceDetails(Object correlationId,
int sequenceNumber,
int sequenceSize) |
MessageBuilder<T> |
readOnlyHeaders(String... readOnlyHeaders)
Specify a list of headers which should be considered as read only
and prohibited from being populated in the 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> |
setCorrelationId(Object correlationId) |
MessageBuilder<T> |
setErrorChannel(MessageChannel errorChannel) |
MessageBuilder<T> |
setErrorChannelName(String errorChannelName) |
MessageBuilder<T> |
setExpirationDate(Date expirationDate) |
MessageBuilder<T> |
setExpirationDate(Long expirationDate) |
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> |
setPriority(Integer priority) |
MessageBuilder<T> |
setReplyChannel(MessageChannel replyChannel) |
MessageBuilder<T> |
setReplyChannelName(String replyChannelName) |
MessageBuilder<T> |
setSequenceNumber(Integer sequenceNumber) |
MessageBuilder<T> |
setSequenceSize(Integer sequenceSize) |
static <T> MessageBuilder<T> |
withPayload(T payload)
Create a builder for a new
Message instance with the provided payload. |
filterAndCopyHeadersIfAbsent
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> 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.T
- The type of the payload.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.T
- The type of the payload.payload
- the payload for the new messagepublic MessageBuilder<T> setHeader(String headerName, @Nullable Object headerValue)
null
, the header will be removed.setHeader
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.headerValue
- The header value.public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue)
setHeaderIfAbsent
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.headerValue
- The header value.public MessageBuilder<T> removeHeaders(String... headerPatterns)
removeHeaders
in class AbstractIntegrationMessageBuilder<T>
headerPatterns
- The header patterns.public MessageBuilder<T> removeHeader(String headerName)
removeHeader
in class AbstractIntegrationMessageBuilder<T>
headerName
- The header name.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.copyHeaders
in class AbstractIntegrationMessageBuilder<T>
headersToCopy
- The headers to copy.MessageHeaders.ID
,
MessageHeaders.TIMESTAMP
public MessageBuilder<T> copyHeadersIfAbsent(@Nullable Map<String,?> headersToCopy)
copyHeadersIfAbsent
in class AbstractIntegrationMessageBuilder<T>
headersToCopy
- The headers to copy.@Nullable protected List<List<Object>> getSequenceDetails()
getSequenceDetails
in class AbstractIntegrationMessageBuilder<T>
@Nullable 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 MessageBuilder<T> pushSequenceDetails(Object correlationId, int sequenceNumber, int sequenceSize)
pushSequenceDetails
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> popSequenceDetails()
popSequenceDetails
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setExpirationDate(Long expirationDate)
setExpirationDate
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setExpirationDate(Date expirationDate)
setExpirationDate
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setCorrelationId(Object correlationId)
setCorrelationId
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setReplyChannel(MessageChannel replyChannel)
setReplyChannel
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setReplyChannelName(String replyChannelName)
setReplyChannelName
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setErrorChannel(MessageChannel errorChannel)
setErrorChannel
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setErrorChannelName(String errorChannelName)
setErrorChannelName
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setSequenceNumber(Integer sequenceNumber)
setSequenceNumber
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setSequenceSize(Integer sequenceSize)
setSequenceSize
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> setPriority(Integer priority)
setPriority
in class AbstractIntegrationMessageBuilder<T>
public MessageBuilder<T> readOnlyHeaders(String... readOnlyHeaders)
readOnlyHeaders
- the list of headers for readOnly
mode.
Defaults to MessageHeaders.ID
and MessageHeaders.TIMESTAMP
.MessageBuilder
IntegrationMessageHeaderAccessor.isReadOnly(String)
public Message<T> build()
build
in class AbstractIntegrationMessageBuilder<T>