Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Faye
Search
Grzesiek Kolodziejczyk
October 20, 2011
Programming
1
210
Faye
Faye, czyli łatwe pubsub z websockets
Grzesiek Kolodziejczyk
October 20, 2011
Tweet
Share
More Decks by Grzesiek Kolodziejczyk
See All by Grzesiek Kolodziejczyk
Working with binary data in Ruby
grk
1
54
Assets on Rails
grk
0
63
Rails Assets
grk
0
120
Other Decks in Programming
See All in Programming
Javaに鉄道指向プログラミング (Railway Oriented Pro gramming) のエッセンスを取り入れる/Bringing the Essence of Railway-Oriented Programming to Java
cocet33000
1
430
コンポーネントライブラリで実現する、アクセシビリティの正しい実装パターン
schktjm
1
700
バリデーションライブラリ徹底比較
nayuta999999
1
540
型付け力を強化するための Hoogle のすゝめ / Boosting Your Type Mastery with Hoogle
guvalif
1
250
Using AI Tools Around Software Development
inouehi
0
280
がんばりすぎないコーディングルール運用術
tsukakei
1
210
ts-morph実践:型を利用するcodemodのテクニック
ypresto
1
570
実はすごいスピードで進化しているCSS
hayato_yokoyama
0
100
人には人それぞれのサービス層がある
shimabox
3
620
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
2
1.8k
単体テストの始め方/作り方
toms74209200
0
330
ワンバイナリWebサービスのススメ
mackee
10
7.6k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Building Applications with DynamoDB
mza
95
6.4k
Rails Girls Zürich Keynote
gr2m
94
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
Designing for humans not robots
tammielis
253
25k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Side Projects
sachag
454
42k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Unsuck your backbone
ammeep
671
58k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Transcript
faye czyli łatwe pub/sub z websockets
faye wiadomości pub/sub serwer: node.js / ruby (rack) backend: ram
/ redis klient: ruby / js fallback do long-polling
faye: archite ktura
faye + redis
private_pub gem dla Rails ułatwia używanie Faye prywatne kanały dwa
tryby publikowania: json, eval
liveblogs tworzenie livebloga wysyłanie wiadomości wyświetlanie livebloga
1 # Run with: rackup faye.ru -s thin -E production
2 require "yaml" 3 require "faye" 4 begin 5 require "private_pub" 6 rescue LoadError 7 require "bundler/setup" 8 require "private_pub" 9 end 10 11 PrivatePub.load_config("config/private_pub.yml", ENV["RAILS_ENV"] || "development") 12 run Faye::RackAdapter.new(:mount => "/faye", :timeout => 45, :extensions => [PrivatePub.faye_extension]) faye.ru
1 development: 2 server: "http://localhost:9292/faye" 3 secret_token: "secret" 4 test:
5 server: "http://localhost:9292/faye" 6 secret_token: "secret" 7 production: 8 server: "http://liveblogs.code-fu.pl:9292/faye" 9 secret_token: "sekret ;)" config/private_pub.yml
1 class Stream 2 include Mongoid::Document 3 include PrivatePub::ViewHelpers 4
5 belongs_to :user 6 embeds_many :messages 7 ... 24 25 def create_message_and_publish(author, message) 26 if self.active 27 m = self.messages.create(a: author, m: message) 28 publish_to "/streams/#{self.id}", m.to_json 29 end 30 end 31 end app/models/stream.rb
1 = subscribe_to "/streams/#{@stream.id}" 2 3 %ul#stream 4 .new_messages 5
.previous_messages 6 - @messages.each do |message| 7 = render 'liveblogs/message', :message => message 8 9 :javascript 46 PrivatePub.subscribe("/streams/#{@stream.id}", function(data, channel) { 47 data = jQuery.parseJSON(data); 48 $(".new_messages").prepend("<li><span class='timestamp'>" + 49 data.t.slice(11,16) + "</span>\n" + 50 "<span class='author'>" + data.a + "</span>\n" + 51 data.m + "</li>").children(":first").hide().fadeIn('slow'); 52 }); app/views/liveblogs/show.html.haml
demo
publish_to + render <% publish_to "/messages/new" do %> $("#chat").append("<%= escape_javascript
render(@messages) %>"); <% end %>
pytania? http://faye.jcoglan.com/ https://github.com/ryanb/private_pub http://liveblogs.code-fu.pl/ http://speakerdeck.com/u/grk/p/faye