public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<java.lang.String> implements SimpMessageSendingOperations
AbstractMessageSendingTemplate
that interprets a
String-based destination as the
DESTINATION_HEADER
to be added to the headers of sent messages.
Also provides methods for sending messages to a user. See
UserDestinationResolver
for more on user destinations.
Modifier and Type | Field and Description |
---|---|
private MessageChannel |
messageChannel |
private long |
sendTimeout |
private java.lang.String |
userDestinationPrefix |
logger
Constructor and Description |
---|
SimpMessagingTemplate(MessageChannel messageChannel)
Create a new
SimpMessagingTemplate instance. |
Modifier and Type | Method and Description |
---|---|
void |
convertAndSendToUser(java.lang.String user,
java.lang.String destination,
java.lang.Object payload)
Send a message to a specific user.
|
void |
convertAndSendToUser(java.lang.String user,
java.lang.String destination,
java.lang.Object payload,
java.util.Map<java.lang.String,java.lang.Object> headers)
Send a message to a specific user.
|
void |
convertAndSendToUser(java.lang.String user,
java.lang.String destination,
java.lang.Object payload,
java.util.Map<java.lang.String,java.lang.Object> headers,
MessagePostProcessor postProcessor)
Send a message to a specific user.
|
void |
convertAndSendToUser(java.lang.String user,
java.lang.String destination,
java.lang.Object payload,
MessagePostProcessor postProcessor)
Send a message to a specific user.
|
protected void |
doSend(java.lang.String destination,
Message<?> message) |
MessageChannel |
getMessageChannel()
Return the configured message channel.
|
long |
getSendTimeout()
Return the configured send timeout (in milliseconds).
|
java.lang.String |
getUserDestinationPrefix()
Return the configured user destination prefix.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
processHeadersToSend(java.util.Map<java.lang.String,java.lang.Object> headers)
Creates a new map and puts the given headers under the key
NATIVE_HEADERS . |
void |
send(Message<?> message)
Send a message to a default destination.
|
void |
setSendTimeout(long sendTimeout)
Specify the timeout value to use for send operations (in milliseconds).
|
void |
setUserDestinationPrefix(java.lang.String prefix)
Configure the prefix to use for destinations targeting a specific user.
|
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, send, setDefaultDestination, setMessageConverter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send
private final MessageChannel messageChannel
private java.lang.String userDestinationPrefix
private volatile long sendTimeout
public SimpMessagingTemplate(MessageChannel messageChannel)
SimpMessagingTemplate
instance.messageChannel
- the message channel (must not be null
)public MessageChannel getMessageChannel()
public void setUserDestinationPrefix(java.lang.String prefix)
The default value is "/user/".
UserDestinationMessageHandler
public java.lang.String getUserDestinationPrefix()
public void setSendTimeout(long sendTimeout)
public long getSendTimeout()
public void send(Message<?> message)
MessageSendingOperations
send
in interface MessageSendingOperations<java.lang.String>
send
in class AbstractMessageSendingTemplate<java.lang.String>
message
- the message to sendprotected void doSend(java.lang.String destination, Message<?> message)
doSend
in class AbstractMessageSendingTemplate<java.lang.String>
public void convertAndSendToUser(java.lang.String user, java.lang.String destination, java.lang.Object payload) throws MessagingException
SimpMessageSendingOperations
convertAndSendToUser
in interface SimpMessageSendingOperations
user
- the user that should receive the message.destination
- the destination to send the message to.payload
- the payload to sendMessagingException
public void convertAndSendToUser(java.lang.String user, java.lang.String destination, java.lang.Object payload, java.util.Map<java.lang.String,java.lang.Object> headers) throws MessagingException
SimpMessageSendingOperations
convertAndSendToUser
in interface SimpMessageSendingOperations
user
- the user that should receive the message.destination
- the destination to send the message to.payload
- the payload to sendheaders
- the message headersMessagingException
public void convertAndSendToUser(java.lang.String user, java.lang.String destination, java.lang.Object payload, MessagePostProcessor postProcessor) throws MessagingException
SimpMessageSendingOperations
convertAndSendToUser
in interface SimpMessageSendingOperations
user
- the user that should receive the message.destination
- the destination to send the message to.payload
- the payload to sendpostProcessor
- a postProcessor to post-process or modify the created messageMessagingException
public void convertAndSendToUser(java.lang.String user, java.lang.String destination, java.lang.Object payload, java.util.Map<java.lang.String,java.lang.Object> headers, MessagePostProcessor postProcessor) throws MessagingException
SimpMessageSendingOperations
convertAndSendToUser
in interface SimpMessageSendingOperations
user
- the user that should receive the message.destination
- the destination to send the message to.payload
- the payload to sendheaders
- the message headerspostProcessor
- a postProcessor to post-process or modify the created messageMessagingException
protected java.util.Map<java.lang.String,java.lang.Object> processHeadersToSend(java.util.Map<java.lang.String,java.lang.Object> headers)
NATIVE_HEADERS
.
Effectively this treats all given headers as headers to be sent out to the
external source.
If the given headers already contain the key
NATIVE_HEADERS
then the same header map is returned (i.e. without any changes).
processHeadersToSend
in class AbstractMessageSendingTemplate<java.lang.String>
headers
- the headers to send or null
null