spring-guides / gs-messaging-stomp-websocket

Using WebSocket to build an interactive web application :: Learn how to the send and receive messages between a browser and the server over a WebSocket

Home Page:http://spring.io/guides/gs/messaging-stomp-websocket/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confused

mschipperheyn opened this issue · comments

Trying to learn stomp. The example uses /hello both as an endpoint and as a MessageMapping. I understand them to be different things.

Indeed the endpoint is the HTTP URL for the SockJS endpoint while the MessageMapping maps the destination from individual STOMP messages that subsequently flow on that SockJS session.

Less confused now ;-) But still struggling with: http://stackoverflow.com/questions/37657783/spring-session-websocket-security-integration-flow It's not a cut and dried topic

Coming at this for the first time, I can relate that the different mappings aren't clear to me.

The client-side application flow seems to be this:

  1. localhost:8080
  2. Connect Button triggers AJAX call to /hello/info
  3. Followed by a 101 Switching Protocols to WS
  4. Then the client subscribes to /topic/greetings
  5. Send Name Button sends a message to /app/hello containing the name from the text field
  6. Client receives greeting message over WS subscription /topic/greetings

That's fairly understandable. But on the server side you've got @MessageMapping("/hello") on the Controller and in your Websocket config: registry.addEndpoint("/hello").withSockJS();

Also the Controller has @sendto("/topic/greetings") and in the Config there is config.enableSimpleBroker("/topic");

Finally there is config.setApplicationDestinationPrefixes("/app"); in the Config.

It's confusing to see the duplicate & overlapping endpoints without a full explanation of what they are all doing.