se2016 exotic oleg gorbunov "action cable"

28
ActionCable и с чем его едят

Upload: inhacking

Post on 11-Apr-2017

64 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: SE2016 Exotic Oleg Gorbunov "Action cable"

ActionCable и с чем его едят

Page 2: SE2016 Exotic Oleg Gorbunov "Action cable"

Main feature

The two star features of Rails 5.0 are as follows:

• Action Cable • API mode

Page 3: SE2016 Exotic Oleg Gorbunov "Action cable"

Что еще за ВебСокеты?

Это та крутая тема, которую чуваки на

Node.js используют?

Я слышал за сокетами будущее

Full-duplex это в 2 раза круче чем half-

duplex, так ведь? Realtime и Full-duplex? звучит круто, добавлю в резюме

Page 4: SE2016 Exotic Oleg Gorbunov "Action cable"

HTML в древности

Simple, stateless, looks like MVP for WEB

Page 5: SE2016 Exotic Oleg Gorbunov "Action cable"

Новые потребности

Клиенту нужно часто отправлять запросы на

сервер

Клиенту нужно часто получать обновления с

сервера

Streaming

в том числе

Page 6: SE2016 Exotic Oleg Gorbunov "Action cable"

Other Realtime solutions

Polling

Long-polling

Server-Sent Events

Page 7: SE2016 Exotic Oleg Gorbunov "Action cable"

Polling

Hey! Hey server! You got any new data? Server? SERVER!.

Page 8: SE2016 Exotic Oleg Gorbunov "Action cable"

Long-polling

Page 9: SE2016 Exotic Oleg Gorbunov "Action cable"

Server-Sent Events (SSE)

ActionController::Live

Page 10: SE2016 Exotic Oleg Gorbunov "Action cable"

How WebSockets Work?

Persistent stateful connectionLightweight metadata

- upgrade request (652 bytes) - and no more

Full-duplex communication

Page 11: SE2016 Exotic Oleg Gorbunov "Action cable"

Caniuseit?

Page 12: SE2016 Exotic Oleg Gorbunov "Action cable"

Откуда растут ноги

Page 13: SE2016 Exotic Oleg Gorbunov "Action cable"

FreeriderRails API, ActionCable, React, MaterialUI

Page 14: SE2016 Exotic Oleg Gorbunov "Action cable"

FreeriderGame page

Page 15: SE2016 Exotic Oleg Gorbunov "Action cable"

API overview

Connection

Channel

Page 16: SE2016 Exotic Oleg Gorbunov "Action cable"

Channels

Page 17: SE2016 Exotic Oleg Gorbunov "Action cable"

Sending Messages

Page 18: SE2016 Exotic Oleg Gorbunov "Action cable"

Javascript

Page 19: SE2016 Exotic Oleg Gorbunov "Action cable"

Code

• 450 LOC of javascript • 2200 LOC of ruby

Page 20: SE2016 Exotic Oleg Gorbunov "Action cable"

Other Options

MessageBus Sync ActionController::Live

faye-websocket-ruby

websocket-rails em-websocket

Page 21: SE2016 Exotic Oleg Gorbunov "Action cable"

MessageBus

• simple api • polling, long-polling or streaming • supports server-server, client-server communication

Page 22: SE2016 Exotic Oleg Gorbunov "Action cable"

Sync

• update partials with web sockets • you need manually call sync_update(@user)

Page 23: SE2016 Exotic Oleg Gorbunov "Action cable"

ActionController::Live• simple API • not for IE • doesn’t work with heroku, unicorn

Page 24: SE2016 Exotic Oleg Gorbunov "Action cable"

faye-websocket-ruby• uses Faye for pub/sub • separate process, no access to rails code • more work to do

Page 25: SE2016 Exotic Oleg Gorbunov "Action cable"

websocket-rails• dead • integrates well with Rails

Page 26: SE2016 Exotic Oleg Gorbunov "Action cable"

em-websocket• looks like faye-websocket-ruby • updated 2 years ago

Page 27: SE2016 Exotic Oleg Gorbunov "Action cable"

Конклюжены

• loosing caching, routing, multiplexing, gzipping and lot more

• good for cases with rapid communication • simple and fun • all-in-box • fast start • rails integration • npm-package • works with heroku • good prospectives

Page 28: SE2016 Exotic Oleg Gorbunov "Action cable"

Sources I am thankful for:1. http://tenderlovemaking.com/2012/07/30/is-it-live.html 2. https://www.sitepoint.com/websockets-in-the-ruby-ecosystem 3. https://www.nateberkopec.com/2015/09/30/action-cable.html 4. http://edgeguides.rubyonrails.org/action_cable_overview.html 5. https://www.sitepoint.com/action-cable-and-websockets-an-in-depth-tutorial 6. https://github.com/websocket-rails/websocket-rails 7. https://github.com/rails/rails/tree/master/actioncable 8. https://github.com/chrismccord/sync 9. https://github.com/SamSaffron/message_bus 10. http://edgeguides.rubyonrails.org/action_cable_overview.html

Author: Oleg Gorbunov game: http://freerider.herokuapp.com email: [email protected] linkedin: https://ua.linkedin.com/in/oleggorbunov