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
57
Assets on Rails
grk
0
66
Rails Assets
grk
0
120
Other Decks in Programming
See All in Programming
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
170
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
560
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
470
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
280
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
610
SwiftUIで本格音ゲー実装してみた
hypebeans
0
530
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
420
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
35k
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
Vibe codingでおすすめの言語と開発手法
uyuki234
0
140
Patterns of Patterns
denyspoltorak
0
390
Implementation Patterns
denyspoltorak
0
140
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
420
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
350
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
410
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
0
34
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
0
68
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
286
14k
Skip the Path - Find Your Career Trail
mkilby
0
28
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
58
41k
Practical Orchestrator
shlominoach
190
11k
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