$30 off During Our Annual Pro Sale. View Details »
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
56
Assets on Rails
grk
0
65
Rails Assets
grk
0
120
Other Decks in Programming
See All in Programming
愛される翻訳の秘訣
kishikawakatsumi
3
320
FluorTracer / RayTracingCamp11
kugimasa
0
230
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
DSPy Meetup Tokyo #1 - はじめてのDSPy
masahiro_nishimi
1
160
How Software Deployment tools have changed in the past 20 years
geshan
0
29k
TypeScriptで設計する 堅牢さとUXを両立した非同期ワークフローの実現
moeka__c
6
3k
tparseでgo testの出力を見やすくする
utgwkk
2
210
dotfiles 式年遷宮 令和最新版
masawada
1
760
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
330
開発に寄りそう自動テストの実現
goyoki
2
920
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
130
AIコーディングエージェント(skywork)
kondai24
0
160
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Code Reviewing Like a Champion
maltzj
527
40k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
How to Ace a Technical Interview
jacobian
280
24k
[SF Ruby Conf 2025] Rails X
palkan
0
510
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
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