SimpMessagingTemplate

An implementation of {@link hunt.stomp.simp.SimpMessageSendingOperations}.

<p>Also provides methods for sending messages to a user. See {@link hunt.stomp.simp.user.UserDestinationResolver UserDestinationResolver} for more on user destinations.

@author Rossen Stoyanchev @since 4.0

Constructors

this
this(MessageChannel messageChannel)

Create a new {@link SimpMessagingTemplate} instance. @param messageChannel the message channel (never {@code null})

Members

Functions

convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload)
Undocumented in source. Be warned that the author may not have intended to support it.
convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, Map!(string, Object) headers)
Undocumented in source. Be warned that the author may not have intended to support it.
convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, MessagePostProcessor postProcessor)
Undocumented in source. Be warned that the author may not have intended to support it.
convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, Map!(string, Object) headers, MessagePostProcessor postProcessor)
Undocumented in source. Be warned that the author may not have intended to support it.
doSend
void doSend(string destination, MessageBase message)
Undocumented in source. Be warned that the author may not have intended to support it.
getHeaderInitializer
MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

getMessageChannel
MessageChannel getMessageChannel()

Return the configured message channel.

getSendTimeout
long getSendTimeout()

Return the configured send timeout (in milliseconds).

getUserDestinationPrefix
string getUserDestinationPrefix()

Return the configured user destination prefix.

processHeadersToSend
Map!(string, Object) processHeadersToSend(Map!(string, Object) headers)

Creates a new map and puts the given headers under the key {@link NativeMessageHeaderAccessor#NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS}. effectively treats the input header map as headers to be sent out to the destination. <p>However if the given headers already contain the key {@code NATIVE_HEADERS NATIVE_HEADERS} then the same headers instance is returned without changes. <p>Also if the given headers were prepared and obtained with {@link SimpMessageHeaderAccessor#getMessageHeaders()} then the same headers instance is also returned without changes.

send
void send(MessageBase message)

If the headers of the given message already contain a {@link hunt.stomp.simp.SimpMessageHeaderAccessor#DESTINATION_HEADER SimpMessageHeaderAccessor#DESTINATION_HEADER} then the message is sent without further changes. <p>If a destination header is not already present ,the message is sent to the configured {@link #setDefaultDestination(Object) defaultDestination} or an exception an {@code IllegalStateException} is raised if that isn't configured. @param message the message to send (never {@code null})

setHeaderInitializer
void setHeaderInitializer(MessageHeaderInitializer headerInitializer)

Configure a {@link MessageHeaderInitializer} to apply to the headers of all messages created through the {@code SimpMessagingTemplate}. <p>By default, this property is not set.

setSendTimeout
void setSendTimeout(long sendTimeout)

Specify the timeout value to use for send operations (in milliseconds).

setUserDestinationPrefix
void setUserDestinationPrefix(string prefix)

Configure the prefix to use for destinations targeting a specific user. <p>The default value is "/user/". @see hunt.stomp.simp.user.UserDestinationMessageHandler

Inherited Members

From SimpMessageSendingOperations

convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload)

Send a message to the given user. @param user the user that should receive the message. @param destination the destination to send the message to. @param payload the payload to send

convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, Map!(string, Object) headers)

Send a message to the given user. <p>By default headers are interpreted as native headers (e.g. STOMP) and are saved under a special key in the resulting Spring {@link hunt.stomp.Message Message}. In effect when the message leaves the application, the provided headers are included with it and delivered to the destination (e.g. the STOMP client or broker). <p>If the map already contains the key {@link hunt.stomp.support.NativeMessageHeaderAccessor#NATIVE_HEADERS "nativeHeaders"} or was prepared with {@link hunt.stomp.simp.SimpMessageHeaderAccessor SimpMessageHeaderAccessor} then the headers are used directly. A common expected case is providing a content type (to influence the message conversion) and native headers. This may be done as follows: <pre class="code"> SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); accessor.setContentType(MimeTypeUtils.TEXT_PLAIN); accessor.setNativeHeader("foo", "bar"); accessor.setLeaveMutable(true); MessageHeaders headers = accessor.getMessageHeaders(); messagingTemplate.convertAndSendToUser(user, destination, payload, headers); </pre> <p><strong>Note:</strong> if the {@code MessageHeaders} are mutable as in the above example, implementations of this interface should take notice and update the headers in the same instance (rather than copy or re-create it) and then set it immutable before sending the final message. @param user the user that should receive the message (must not be {@code null}) @param destination the destination to send the message to (must not be {@code null}) @param payload the payload to send (may be {@code null}) @param headers the message headers (may be {@code null})

convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, MessagePostProcessor postProcessor)

Send a message to the given user. @param user the user that should receive the message (must not be {@code null}) @param destination the destination to send the message to (must not be {@code null}) @param payload the payload to send (may be {@code null}) @param postProcessor a postProcessor to post-process or modify the created message

convertAndSendToUser
void convertAndSendToUser(string user, string destination, Object payload, Map!(string, Object) headers, MessagePostProcessor postProcessor)

Send a message to the given user. <p>See {@link #convertAndSend(Object, Object, java.util.Map)} for important notes regarding the input headers. @param user the user that should receive the message @param destination the destination to send the message to @param payload the payload to send @param headers the message headers @param postProcessor a postProcessor to post-process or modify the created message

Meta