接口 SimpMessageSendingOperations
- 所有超级接口:
MessageSendingOperations<String>
- 所有已知实现类:
SimpMessagingTemplate
public interface SimpMessageSendingOperations extends MessageSendingOperations<String>
A specialization ofMessageSendingOperations
with methods for use with the Spring Framework support for Simple Messaging Protocols (like STOMP).For more on user destinations see
UserDestinationResolver
.Generally it is expected the user is the one authenticated with the WebSocket session (or by extension the user authenticated with the handshake request that started the session). However if the session is not authenticated, it is also possible to pass the session id (if known) in place of the user name. Keep in mind though that in that scenario, you must use one of the overloaded methods that accept headers making sure the
sessionId
header has been set accordingly.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 void
convertAndSendToUser(String user, String destination, Object payload)
Send a message to the given user.void
convertAndSendToUser(String user, String destination, Object payload, Map<String,Object> headers)
Send a message to the given user.void
convertAndSendToUser(String user, String destination, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor)
Send a message to the given user.void
convertAndSendToUser(String user, String destination, Object payload, MessagePostProcessor postProcessor)
Send a message to the given user.从接口继承的方法 org.springframework.messaging.core.MessageSendingOperations
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send, send
方法详细资料
convertAndSendToUser
void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException
Send a message to the given user.- 参数:
user
- the user that should receive the message.destination
- the destination to send the message to.payload
- the payload to send- 抛出:
MessagingException
convertAndSendToUser
void convertAndSendToUser(String user, String destination, Object payload, Map<String,Object> headers) throws MessagingException
Send a message to the given user.By default headers are interpreted as native headers (e.g. STOMP) and are saved under a special key in the resulting Spring
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).If the map already contains the key
"nativeHeaders"
or was prepared withSimpMessageHeaderAccessor
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: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);
Note: if the
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.- 参数:
user
- the user that should receive the message (must not benull
)destination
- the destination to send the message to (must not benull
)payload
- the payload to send (may benull
)headers
- the message headers (may benull
)- 抛出:
MessagingException
convertAndSendToUser
void convertAndSendToUser(String user, String destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException
Send a message to the given user.- 参数:
user
- the user that should receive the message (must not benull
)destination
- the destination to send the message to (must not benull
)payload
- the payload to send (may benull
)postProcessor
- a postProcessor to post-process or modify the created message- 抛出:
MessagingException
convertAndSendToUser
void convertAndSendToUser(String user, String destination, Object payload, @Nullable Map<String,Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingException
Send a message to the given user.See
MessageSendingOperations.convertAndSend(Object, Object, java.util.Map)
for important notes regarding the input headers.- 参数:
user
- the user that should receive the messagedestination
- the destination to send the message topayload
- the payload to sendheaders
- the message headerspostProcessor
- a postProcessor to post-process or modify the created message- 抛出:
MessagingException