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
56
Assets on Rails
grk
0
65
Rails Assets
grk
0
120
Other Decks in Programming
See All in Programming
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
230
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
200
SpecKitでどこまでできる? コストはどれくらい?
leveragestech
0
720
CSC305 Lecture 04
javiergs
PRO
0
270
Your Perfect Project Setup for Angular @BASTA! 2025 in Mainz
manfredsteyer
PRO
0
170
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
680
理論と実務のギャップを超える
eycjur
0
130
Swift Concurrency - 状態監視の罠
objectiveaudio
2
520
ポスターセッション: 「まっすぐ行って、右!」って言ってラズパイカーを動かしたい 〜生成AI × Raspberry Pi Pico × Gradioの試作メモ〜
komofr
0
1.3k
高度なUI/UXこそHotwireで作ろう Kaigi on Rails 2025
naofumi
4
4k
Go言語はstack overflowの夢を見るか?
logica0419
0
240
CSC305 Lecture 05
javiergs
PRO
0
210
Featured
See All Featured
Facilitating Awesome Meetings
lara
56
6.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
Context Engineering - Making Every Token Count
addyosmani
5
230
Fireside Chat
paigeccino
40
3.7k
How to Ace a Technical Interview
jacobian
280
24k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
KATA
mclloyd
32
15k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Building Applications with DynamoDB
mza
96
6.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Music & Morning Musume
bryan
46
6.8k
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