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})
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})