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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
59
Assets on Rails
grk
0
67
Rails Assets
grk
0
120
Other Decks in Programming
See All in Programming
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
970
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
110
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
MUSUBIXとは
nahisaho
0
130
2026年 エンジニアリング自己学習法
yumechi
0
130
Oxlintはいいぞ
yug1224
5
1.3k
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
580
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
54
From π to Pie charts
rasagy
0
120
Utilizing Notion as your number one productivity tool
mfonobong
2
210
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
230
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
BBQ
matthewcrist
89
10k
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