Top Description Methods
org.springframework.messaging.simp

public Interface SimpMessageSendingOperations

extends MessageSendingOperations<String>
Known Direct Implementers
org.springframework.messaging.simp.SimpMessagingTemplate
Imports
java.util.Map, org.springframework.lang.Nullable, org.springframework.messaging.MessagingException, org.springframework.messaging.core.MessagePostProcessor, .MessageSendingOperations

A specialization of MessageSendingOperations 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.

Author
Rossen Stoyanchev
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public void
convertAndSendToUser(String
the user that should receive the message.
user
,
String
the destination to send the message to.
destination
,
Object
the payload to send
payload
)

Send a message to the given user.

public void
convertAndSendToUser(String
the user that should receive the message (must not be null)
user
,
String
the destination to send the message to (must not be null)
destination
,
Object
the payload to send (may be null)
payload
,
Map<String, Object>
the message headers (may be null)
headers
)

Send a message to the given user.

public void
convertAndSendToUser(String
the user that should receive the message (must not be null)
user
,
String
the destination to send the message to (must not be null)
destination
,
Object
the payload to send (may be null)
payload
,
MessagePostProcessor
a postProcessor to post-process or modify the created message
postProcessor
)

Send a message to the given user.

public void
convertAndSendToUser(String
the user that should receive the message
user
,
String
the destination to send the message to
destination
,
Object
the payload to send
payload
,
Map<String, Object>
the message headers
headers
,
MessagePostProcessor
a postProcessor to post-process or modify the created message
postProcessor
)

Send a message to the given user.

Inherited from org.springframework.messaging.core.MessageSendingOperations:
convertAndSendconvertAndSendconvertAndSendconvertAndSendconvertAndSendconvertAndSendsendsend

Method Detail

convertAndSendToUserback to summary
public void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException

Send a message to the given user.

Parameters
user:String

the user that should receive the message.

destination:String

the destination to send the message to.

payload:Object

the payload to send

convertAndSendToUserback to summary
public 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 with 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:

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.

Parameters
user:String

the user that should receive the message (must not be null)

destination:String

the destination to send the message to (must not be null)

payload:Object

the payload to send (may be null)

headers:Map<String, Object>

the message headers (may be null)

convertAndSendToUserback to summary
public void convertAndSendToUser(String user, String destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException

Send a message to the given user.

Parameters
user:String

the user that should receive the message (must not be null)

destination:String

the destination to send the message to (must not be null)

payload:Object

the payload to send (may be null)

postProcessor:MessagePostProcessor

a postProcessor to post-process or modify the created message

convertAndSendToUserback to summary
public void convertAndSendToUser(String user, String destination, Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) throws MessagingException

Send a message to the given user.

See convertAndSend(Object, Object, java.util.Map) for important notes regarding the input headers.

Parameters
user:String

the user that should receive the message

destination:String

the destination to send the message to

payload:Object

the payload to send

headers:Map<String, Object>

the message headers

postProcessor:MessagePostProcessor

a postProcessor to post-process or modify the created message