Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring + WebSocket integration

1,177 views

Published on

Comet approaches overview, benefits and drawbacks: polling, long-polling, HTML5 server-side events, HTML5 WebSocket.
Example of WebSocket and Spring 4 integration using STOMP protocol.

Published in: Software
  • Be the first to comment

Spring + WebSocket integration

  1. 1. Spring + WebSocket integration SEMENOV OLEKSANDR
  2. 2. Agenda 1) The problem of synchronous data exchange model 2) Existing solutions 3) WebSocket 4) Subprotocols: STOMP 5) Spring MVC + WebSocket architecture 6) Drawbacks 7) Showcase
  3. 3. The problem HTTP is synchronous, but sometimes asynchronous data receiving from server is required
  4. 4. The problem
  5. 5. Existing solutions Several ways to solve it: 1) Polling 2) Long polling 3) Endless iframe 4) HTML5: Server Side Events 5) HTML5: WebSocket
  6. 6. Polling
  7. 7. Long polling
  8. 8. Polling/long polling. Drawbacks Self-initiated DDoS attack!
  9. 9. Polling/long polling. Drawbacks 1) Network overhead a) SSL handshake can be initiated each time, and it is expensive 2) User presence tracking is complicated 3) In case of load balancer, each time user will be connected to different server
  10. 10. Server Side Events
  11. 11. Server Side Events. API
  12. 12. Server Side Events. Drawbacks Browser support is limited
  13. 13. Any alternatives?
  14. 14. WebSocket
  15. 15. WebSocket features 1) Bidirectional 2) Binary 3) No data overhead 4) Persistent connection 5) Supported by most proxies and load-balancers
  16. 16. WebSocket handshake
  17. 17. WebSocket handshake
  18. 18. WebSocket advantages
  19. 19. WebSocket vs REST approach REST 1) Each URL mapped to resource 2) Each HTTP method has predefined semantics WebSocket 1) Single URL for handshake 2) No predefined semantics
  20. 20. What does it mean? Communications via WebSocket is much closer to messaging approach* But no concrete messaging protocols are defined
  21. 21. WebSocket subprotocols 1) WAMP – provides RPC + messaging features. 2) STOMP – provides messaging features only. Can be easily integrated with message brokers like ActiveMQ, RabbitMQ etc. 3) 20+ other subprotocols
  22. 22. STOMP
  23. 23. Integration with Spring MVC Client side 1) stomp.js library Server side 1) Spring 4+
  24. 24. Client-side configuration
  25. 25. Server-side configuration
  26. 26. Server-side configuration
  27. 27. Other features 1) Exception handling 2) Flexible destinations 3) External message broker pluging-in
  28. 28. Internal architecture
  29. 29. External broker case
  30. 30. Drawbacks What if you want connect directly to external message broker and put message there, not via WebSocket endpoint?
  31. 31. It is impossible with current Spring architecture. Workarounds required.
  32. 32. Conclusions 1) WebSocket is standardized technology for bidirectional data exchange in web. 2) WebSocket is fast and low latency 3) Spring 4+ easily integrates with websockets using STOMP subprotocol. 4) Spring 4+ internal architecture is not ideal
  33. 33. Thank you!

×