Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SockJS - WebSocket Emulation simple, stupid; krtconf Nov-2011

D4e1d473a995ef37b3e03e9e6006c3e3?s=47 majek04
November 14, 2011

SockJS - WebSocket Emulation simple, stupid; krtconf Nov-2011

D4e1d473a995ef37b3e03e9e6006c3e3?s=128

majek04

November 14, 2011
Tweet

Transcript

  1. SockJS WebSocket emulation kept simple, stupid Marek Majkowski marek@rabbitmq.com Tuesday,

    8 November 11
  2. The plan • WebSockets • SockJS • Messaging models Tuesday,

    8 November 11
  3. Load Balancer Web server Web server Web server Message bus

    @sockjs http://sockjs.org github.com/sockjs Tuesday, 8 November 11
  4. #sockjs Tuesday, 8 November 11

  5. #sockjs Tuesday, 8 November 11

  6. #sockjs WebSockets hixie-75 4 5.0.0 hixie-76 4 (disabled) 6 5.0.1

    11 (disabled) hybi-07 6 hybi-10 7 14 10-dev hybi-17 16-dev Tuesday, 8 November 11
  7. #sockjs WebSockets hixie-75 4 5.0.0 hixie-76 4 (disabled) 6 5.0.1

    11 (disabled) hybi-07 6 hybi-10 7 14 10-dev hybi-17 16-dev { { Tuesday, 8 November 11
  8. #sockjs FF and Proxies CONNECT sockjs1.popcnt.org:80 HTTP/1.1 Host: sockjs1.popcnt.org Proxy-Connection:

    keep-alive GET /echo/855/duzzy2p1/websocket HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: sockjs1.popcnt.org Origin: http://sockjs.popcnt.org Sec-WebSocket-Key1: 22p/ D"47900%n7 r90. Sec-WebSocket-Key2: m49" 5 f 24772 Ra GET /echo/070/lm6wwjpr/websocket HTTP/1.1 Host: sockjs1.popcnt.org User-Agent: [...] Gecko/20100101 Firefox/6.0.2 Accept: text/html,application/xhtml [...] Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Sec-WebSocket-Version: 7 Sec-WebSocket-Origin: http://sockjs.popcnt.org Sec-WebSocket-Key: bzG4fOYXabSiy42uFj6vjA== Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Connection: Upgrade HTTP/1.0 400 Bad Request Server: squid/2.7.STABLE9 Date: Wed, 21 Sep 2011 06:16:10 GMT Content-Type: text/html Content-Length: 1943 X-Squid-Error: ERR_INVALID_REQ 0 X-Cache: MISS from mrstu Connection: close Tuesday, 8 November 11
  9. #sockjs • #1 Realtime web: Not there yet! Tuesday, 8

    November 11
  10. #sockjs SockJS Load Balancer Web server Web server Web server

    Message bus Tuesday, 8 November 11
  11. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  12. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  13. #sockjs WebSocket like API <script> var sock = new SockJS('http://mydomain.com/my_prefix');

    sock.onopen = function() { console.log('open'); }; sock.onmessage = function(e) { console.log('message', e.data); }; sock.onclose = function() { console.log('close'); }; </script> Tuesday, 8 November 11
  14. #sockjs WebSocket like API var http = require('http'); var sockjs

    = require('sockjs'); var echo = sockjs.createServer(sockjs_opts); echo.on('connection', function(conn) { conn.on('data', function(message) { conn.write(message); }); conn.on('close', function() {}); }); var server = http.createServer(); echo.installHandlers(server, {prefix:'[/]echo'}); server.listen(9999, '0.0.0.0'); Tuesday, 8 November 11
  15. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  16. #sockjs Fallbacks Tuesday, 8 November 11

  17. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  18. #sockjs Cross domain Load Balancer Web server Web server Web

    server Message bus Tuesday, 8 November 11
  19. #sockjs Cross domain Load Balancer Web server Web server Web

    server Database Load Balancer Async server Message bus Tuesday, 8 November 11
  20. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  21. #sockjs Load blancer Load Balancer Web server Web server Web

    server Message bus Tuesday, 8 November 11
  22. #sockjs ? Load blancer Load Balancer Web server Web server

    Web server Message bus Tuesday, 8 November 11
  23. #sockjs Load balancer var sockjs_opts = { [...] disabled_transports: ['websocket']

    }; Tuesday, 8 November 11
  24. #sockjs Sticky sessions Load Balancer Web server Web server Web

    server Message bus • prefix based • JSESSIONID cookie Tuesday, 8 November 11
  25. #sockjs Sticky sessions var sockjs_opts = { [...] cookies: true

    }; Tuesday, 8 November 11
  26. #sockjs Deployment Load Balancer Web server Web server Web server

    Message bus Tuesday, 8 November 11
  27. #sockjs Load Balancer Web server Web server Web server Database

    Load Balancer Async server Message bus Deployment Tuesday, 8 November 11
  28. #sockjs ws:// Load Balancer Web server Web server Web server

    Message bus ws:// ws:// Load Balancer SockJS proxy Deployment Tuesday, 8 November 11
  29. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  30. #sockjs SockJS protocol • XXX screenshot Tuesday, 8 November 11

  31. #sockjs QUnit tests Tuesday, 8 November 11

  32. #sockjs Polyglot • Server side: • simple, testable • Supported:

    • Node.js, Erlang, LUA, Ruby* Tuesday, 8 November 11
  33. #sockjs SockJS 1. WebSocket like API 2. Fallbacks 3. Cross

    domain support 4. Scalability explained 5. Specified protocol, polyglot 6. No messaging model Tuesday, 8 November 11
  34. #sockjs Transport Pub/Sub Work Queues Presence Value + Updates No

    messaging model Tuesday, 8 November 11
  35. #sockjs Transport Pub/Sub Work Queues Presence Value + Updates No

    messaging model Tuesday, 8 November 11
  36. #sockjs Load Balancer Web server Web server Web server Database

    Service Web Messaging Service Tuesday, 8 November 11
  37. #sockjs Load Balancer Web server Web server Web server Database

    Service Web Messaging Service Tuesday, 8 November 11
  38. #sockjs Tuesday, 8 November 11

  39. #sockjs Google App Engine • Simplex • No broadcast •

    No presence user App Tuesday, 8 November 11
  40. #sockjs PubNub • Duplex • Broadcast • No permissions •

    No identity subscribe("/topic") publish("/topic") App Tuesday, 8 November 11
  41. #sockjs Pusher • Simplex • Broadcast • Permissions * •

    Identity * • Presence * App publish("/topic") subscribe("/topic") Tuesday, 8 November 11
  42. #sockjs Tuesday, 8 November 11

  43. #sockjs Chat app • /chat • /roster Tuesday, 8 November

    11
  44. #sockjs Chat app • /chat • /roster Tuesday, 8 November

    11
  45. #sockjs Chat app • /chat • /roster Tuesday, 8 November

    11
  46. #sockjs 1. Authorisation 2. Value + updates 3. Presence App

    subscribe("/chat") subscribe("/roster") index.html Tuesday, 8 November 11
  47. #sockjs 1. Authorisation 2. Value + updates 3. Presence Tuesday,

    8 November 11
  48. #sockjs Authorization App subscribe("/chat") subscribe("/roster") index.html GET Tuesday, 8 November

    11
  49. #sockjs App 2. identity and permissions 4. 3. token token

    1. GET Authorization Tuesday, 8 November 11
  50. #sockjs 1. Authorisation 2. Value + updates 3. Presence Tuesday,

    8 November 11
  51. #sockjs V+U: Application subscribe("/chat") …updates from "chat"… get historical data

    for "/chat" App [...] <dwww> Version/11.51 <majek> ah, boring then. <dwww> i copypasted what qunit page reports <dwww> ;) <majek> No browser works on your computer :) Tuesday, 8 November 11
  52. #sockjs V+U: Application } subscribe("/chat") …updates from "chat"… get historical

    data for "/chat" App [...] <dwww> Version/11.51 <majek> ah, boring then. <dwww> i copypasted what qunit page reports <dwww> ;) <majek> No browser works on your computer :) Tuesday, 8 November 11
  53. #sockjs 1. Authorisation 2. Value + updates 3. Presence Tuesday,

    8 November 11
  54. #sockjs Presence naively subscribe("/chat") subscribe("/roster") send("/roster","Marek entered") …updates from "chat"…

    …updates from "roster"… Tuesday, 8 November 11
  55. #sockjs Presence naively subscribe("/chat") subscribe("/roster") send("/roster","Marek entered") …updates from "chat"…

    …updates from "roster"… Tuesday, 8 November 11
  56. #sockjs Presence naively subscribe("/chat") subscribe("/roster") send("/roster","Marek entered") …updates from "chat"…

    …updates from "roster"… } Tuesday, 8 November 11
  57. #sockjs Service? Load Balancer Web server Web server Web server

    Database Service Tuesday, 8 November 11
  58. #sockjs SockJS Message bus Application Messaging Web server Application Messaging

    Web server Tuesday, 8 November 11
  59. #sockjs • #3 Realtime web: Not there yet! Tuesday, 8

    November 11
  60. #sockjs Tuesday, 8 November 11

  61. #sockjs Tuesday, 8 November 11

  62. #sockjs @sockjs http://sockjs.org github.com/sockjs/sockjs-client Tuesday, 8 November 11

  63. #sockjs Tuesday, 8 November 11