+ All Categories
Home > Software > Spring + WebSocket integration

Spring + WebSocket integration

Date post: 21-Jan-2017
Category:
Upload: oleksandr-semenov
View: 150 times
Download: 1 times
Share this document with a friend
33
Spring + WebSocket integration SEMENOV OLEKSANDR
Transcript
Page 1: Spring + WebSocket integration

Spring + WebSocket integrationSEMENOV OLEKSANDR

Page 2: Spring + WebSocket integration

Agenda1) The problem of synchronous data exchange model2) Existing solutions3) WebSocket4) Subprotocols: STOMP5) Spring MVC + WebSocket architecture6) Drawbacks7) Showcase

Page 3: Spring + WebSocket integration

The problem

HTTP is synchronous, but sometimes asynchronous data receiving from server is required

Page 4: Spring + WebSocket integration

The problem

Page 5: Spring + WebSocket integration

Existing solutionsSeveral ways to solve it:

1) Polling2) Long polling3) Endless iframe4) HTML5: Server Side Events5) HTML5: WebSocket

Page 6: Spring + WebSocket integration

Polling

Page 7: Spring + WebSocket integration

Long polling

Page 8: Spring + WebSocket integration

Polling/long polling. Drawbacks

Self-initiated DDoS attack!

Page 9: Spring + WebSocket integration

Polling/long polling. Drawbacks

1) Network overheada) 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

Page 10: Spring + WebSocket integration

Server Side Events

Page 11: Spring + WebSocket integration

Server Side Events. API

Page 12: Spring + WebSocket integration

Server Side Events. Drawbacks

Browser support is limited

Page 13: Spring + WebSocket integration

Any alternatives?

Page 14: Spring + WebSocket integration

WebSocket

Page 15: Spring + WebSocket integration

WebSocket features1) Bidirectional

2) Binary

3) No data overhead

4) Persistent connection

5) Supported by most proxies and load-balancers

Page 16: Spring + WebSocket integration

WebSocket handshake

Page 17: Spring + WebSocket integration

WebSocket handshake

Page 18: Spring + WebSocket integration

WebSocket advantages

Page 19: Spring + WebSocket integration

WebSocket vs REST approach

REST1) Each URL mapped to resource

2) Each HTTP method has predefined semantics

WebSocket3) Single URL for handshake

4) No predefined semantics

Page 20: Spring + WebSocket integration

What does it mean?

Communications via WebSocket is much closer to messaging approach*

But no concrete messaging protocols are defined

Page 21: Spring + WebSocket integration

WebSocket subprotocols1) 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

Page 22: Spring + WebSocket integration

STOMP

Page 23: Spring + WebSocket integration

Integration with Spring MVC

Client side 1) stomp.js library

Server side 1) Spring 4+

Page 24: Spring + WebSocket integration

Client-side configuration

Page 25: Spring + WebSocket integration

Server-side configuration

Page 26: Spring + WebSocket integration

Server-side configuration

Page 27: Spring + WebSocket integration

Other features 1) Exception handling

2) Flexible destinations

3) External message broker pluging-in

Page 28: Spring + WebSocket integration

Internal architecture

Page 29: Spring + WebSocket integration

External broker case

Page 30: Spring + WebSocket integration

Drawbacks

What if you want connect directly to external message broker and put message there, not via WebSocket endpoint?

Page 31: Spring + WebSocket integration

It is impossible with current Spring architecture. Workarounds required.

Page 32: Spring + WebSocket integration

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

Page 33: Spring + WebSocket integration

Thank you!


Recommended