title: How does Spring WebSocket send message to a specific user?
body: <p>I am reading the book <a href="https://www.manning.com/books/spring-in-action-fourth-edition" rel="noreferrer">Spring in Action 4</a> to work with STOMP messaging over WebSocket.</p>
  
  <p>Suppose the <code>user destination prefix is set as "/user"</code> as below:</p>
  
  <pre><code>registry.setUserDestinationPrefix("/user");
  </code></pre>
  
  <p>Then client subscribes to a destination with below JavaScript code:</p>
  
  <pre><code>stomp.subscribe("/user/queue/notifications", handleNotifications);
  </code></pre>
  
  <p>Then on the server, the <code>actual</code> destination that <code>the</code> client subscribes to should be <strong><em>derived</em></strong> from its session, maybe like this:</p>
  
  <pre><code>/queue/notifications-user6hr83v6t  --- (1)
  </code></pre>
  
  <p>Then I use the <code>SimpMessagingTemplate</code> to send message to that user:</p>
  
  <pre><code>messaging.convertAndSendToUser( username, "/queue/notifications",
                             new Notification("You just got mentioned!"));
  </code></pre>
  
  <p>Then the message will be sent to destination like this:</p>
  
  <pre><code>/user/&lt;username&gt;/queue/notifications  ---(2)
  </code></pre>
  
  <p>Well, the two destinations <code>(1)</code> and <code>(2)</code> look different, how could the message ever reach the client?</p>