SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Faye
simple pub/sub messaging
http://faye.jcoglan.com/
• Publish-subscribe messaging system
• Based on the Bayeux protocol
• Servers/clients in Ruby and Javascript
npm install faye




gem install faye
Server
var Faye   = require('faye')
var server = new Faye.NodeAdapter({ mount: '/faye' })

server.listen(8000)
require 'faye'

server = Faye::RackAdapter.new(:mount => '/faye')
server.listen(8000)
Client
var Faye   = require('faye')
var client = new Faye.Client('http://localhost:8000/faye')

// subscribe to a channel
client.subscribe('/messages', function(message) {
   console.log('We got a message: ' + message.text)
})

// publish to a channel
client.publish('/messages', {
   text: 'HAI!'
})
<script type="text/javascript"
        src="http://localhost:8000/faye/client.js"></script>

<script type="text/javascript">
  var client = new Faye.Client('http://localhost:8000/faye')

  client.subscribe('/messages', function(message) {
     alert('We got a message: ' + message.text)
  })
</script>
require 'faye'
require 'eventmachine'

EM.run {
  client = Faye::Client.new('http://localhost:8000/faye')

    # subscribe to a channel
    client.subscribe('/messages') do |message|
      puts message.inspect
    end

    # publish to a channel
    client.publish('/messages', { 'text' => 'HAI!' })
}
Example App
• Simple chat-room application
 • Sinatra
 • Faye
require 'sinatra'

get '/' do
  erb :index
end
var Faye   = require('faye')
var server = new Faye.NodeAdapter({ mount: '/faye' })
server.listen(8000)
<!DOCTYPE html>
<html>
<head>
  <title>Chattr</title>
  <link rel="stylesheet" href="chattr.css" type="text/css" media="screen" />
</head>
<body>
  <h1>Lets Chat...</h1>

  <ul id="chat"></ul>
  <form id="new_message" action="#" method="get" accept-charset="utf-8">
    <input type="text" name="message" id="message" value="" />
    <input type="submit" name="send" id="send" value="Send" />
  </form>

  <script src="jquery.min.js" charset="utf-8"></script>
  <script src="http://localhost:8000/faye/client.js" charset="utf-8"></script>
  <script src="chattr.js" charset="utf-8"></script>
</body>
</html>
var client = new Faye.Client('http://localhost:8000/faye')

// Publish a message...
$('#new_message').bind('submit',function() {
  var now     = new Date()
  var message = {
    content: $('#message').val(),
    timestamp: now.getHours() + ":" + now.getMinutes()
  }

     client.publish('/messages', message)
     $('#message').val('')
     return false
})

// Subscribe to message feed...
client.subscribe('/messages', function(message) {
  var str = ''
  str += '<li>'
  str += ' <span class="created_at">'+ message.timestamp +'</span>'
  str += ' '+ message.content
  str += '</li>'

     $('#chat').append(str)
})
Demo
Server
Events

• handshake
• subscribe
• unsubscribe
• publish
• disconnect
var Faye   = require('faye')
var server = new Faye.NodeAdapter({ mount: '/faye' })
server.listen(8000)

server.bind('handshake', function(client_id) {
   console.log("[handshake] - client: '"+ client_id +"'")
})

server.bind('subscribe', function(client_id, channel) {
   console.log("[subscribe] - client: '"+ client_id +"', channel: '"+ channel +"'")
})

server.bind('unsubscribe', function(client_id, channel) {
   console.log("[unsubscribe] - client: '"+ client_id +"', channel: '"+ channel
+"'")
})

server.bind('publish', function(client_id, channel, data) {
   console.log("[publish] - client: '"+ client_id +"', channel: '"+ channel +"'")
   console.log("[publish] - data:")
   console.log(data)
})

server.bind('disconnect', function(client_id) {
   console.log("[disconnect] - client: '"+ client_id +"'")
})
require 'faye'
require 'logger'

Faye::WebSocket.load_adapter('thin')
faye = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)

log = Logger.new(STDOUT)
log.level = Logger::INFO

faye.bind(:handshake) do |client_id|
  log.info("[handshake] - client: '#{client_id}'")
end

faye.bind(:subscribe) do |client_id,channel|
  log.info("[subscribe] - client: '#{client_id}', channel: '#{channel}'")
end

faye.bind(:unsubscribe) do |client_id,channel|
  log.info("[unsubscribe] - client: '#{client_id}', channel: '#{channel}'")
end

faye.bind(:publish) do |client_id,channel,data|
  log.info("[publish] - client: '#{client_id}', channel: '#{channel}', data: '#
{data.inspect}'")
end

faye.bind(:disconnect) do |client_id|
  log.info("[disconnect] - client: '#{client_id}'")
end

run faye
Extensions

• Override default behaviour...
 • incoming()
 • outgoing()
Engines


• Change the back-end...
 • faye-redis
var faye       = require('faye')
var faye_redis = require('faye-redis')

var server = new faye.NodeAdapter({
   mount:   '/faye',
   timeout: 25,
   engine:  {
     type:  faye_redis,
     host:  'localhost',
     port:  6379
   }
})
server.listen(8000)
require 'faye'
require 'faye-redis'

server = Faye::RackAdapter.new(
  :mount   => '/faye',
  :timeout => 25,
  :engine => {
    :type => Faye::Redis,
    :host => 'localhost',
    :port => 6379
  }
)
server.listen(8000)
An Introduction to Faye

Weitere ähnliche Inhalte

Ähnlich wie An Introduction to Faye

Server Side Events
Server Side EventsServer Side Events
Server Side Eventsthepilif
 
[WSO2 Integration Summit Madrid 2019] Integration + Ballerina
[WSO2 Integration Summit Madrid 2019] Integration + Ballerina[WSO2 Integration Summit Madrid 2019] Integration + Ballerina
[WSO2 Integration Summit Madrid 2019] Integration + BallerinaWSO2
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-KjaerCOMMON Europe
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Top 10 F5 iRules to migrate to a modern load balancing platform
Top 10 F5 iRules to migrate to a modern load balancing platformTop 10 F5 iRules to migrate to a modern load balancing platform
Top 10 F5 iRules to migrate to a modern load balancing platformAvi Networks
 
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsBastian Hofmann
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Ismael Celis
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]Eleanor McHugh
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rackdanwrong
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기JeongHun Byeon
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Bart Uelen
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebRobert Nyman
 
feature toggles for ops
feature toggles for opsfeature toggles for ops
feature toggles for opsBram Vogelaar
 

Ähnlich wie An Introduction to Faye (20)

Server Side Events
Server Side EventsServer Side Events
Server Side Events
 
[WSO2 Integration Summit Madrid 2019] Integration + Ballerina
[WSO2 Integration Summit Madrid 2019] Integration + Ballerina[WSO2 Integration Summit Madrid 2019] Integration + Ballerina
[WSO2 Integration Summit Madrid 2019] Integration + Ballerina
 
web3j Overview
web3j Overviewweb3j Overview
web3j Overview
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Top 10 F5 iRules to migrate to a modern load balancing platform
Top 10 F5 iRules to migrate to a modern load balancing platformTop 10 F5 iRules to migrate to a modern load balancing platform
Top 10 F5 iRules to migrate to a modern load balancing platform
 
NodeJS "Web en tiempo real"
NodeJS "Web en tiempo real"NodeJS "Web en tiempo real"
NodeJS "Web en tiempo real"
 
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web Apps
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 
MMC Rest API - Servers
MMC Rest API - ServersMMC Rest API - Servers
MMC Rest API - Servers
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
 
Payments On Rails
Payments On RailsPayments On Rails
Payments On Rails
 
feature toggles for ops
feature toggles for opsfeature toggles for ops
feature toggles for ops
 

Kürzlich hochgeladen

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Kürzlich hochgeladen (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

An Introduction to Faye

  • 2. • Publish-subscribe messaging system • Based on the Bayeux protocol • Servers/clients in Ruby and Javascript
  • 3. npm install faye gem install faye
  • 5. var Faye = require('faye') var server = new Faye.NodeAdapter({ mount: '/faye' }) server.listen(8000)
  • 6. require 'faye' server = Faye::RackAdapter.new(:mount => '/faye') server.listen(8000)
  • 8. var Faye = require('faye') var client = new Faye.Client('http://localhost:8000/faye') // subscribe to a channel client.subscribe('/messages', function(message) { console.log('We got a message: ' + message.text) }) // publish to a channel client.publish('/messages', { text: 'HAI!' })
  • 9. <script type="text/javascript" src="http://localhost:8000/faye/client.js"></script> <script type="text/javascript"> var client = new Faye.Client('http://localhost:8000/faye') client.subscribe('/messages', function(message) { alert('We got a message: ' + message.text) }) </script>
  • 10. require 'faye' require 'eventmachine' EM.run { client = Faye::Client.new('http://localhost:8000/faye') # subscribe to a channel client.subscribe('/messages') do |message| puts message.inspect end # publish to a channel client.publish('/messages', { 'text' => 'HAI!' }) }
  • 12. • Simple chat-room application • Sinatra • Faye
  • 13. require 'sinatra' get '/' do erb :index end
  • 14. var Faye = require('faye') var server = new Faye.NodeAdapter({ mount: '/faye' }) server.listen(8000)
  • 15. <!DOCTYPE html> <html> <head> <title>Chattr</title> <link rel="stylesheet" href="chattr.css" type="text/css" media="screen" /> </head> <body> <h1>Lets Chat...</h1> <ul id="chat"></ul> <form id="new_message" action="#" method="get" accept-charset="utf-8"> <input type="text" name="message" id="message" value="" /> <input type="submit" name="send" id="send" value="Send" /> </form> <script src="jquery.min.js" charset="utf-8"></script> <script src="http://localhost:8000/faye/client.js" charset="utf-8"></script> <script src="chattr.js" charset="utf-8"></script> </body> </html>
  • 16. var client = new Faye.Client('http://localhost:8000/faye') // Publish a message... $('#new_message').bind('submit',function() { var now = new Date() var message = { content: $('#message').val(), timestamp: now.getHours() + ":" + now.getMinutes() } client.publish('/messages', message) $('#message').val('') return false }) // Subscribe to message feed... client.subscribe('/messages', function(message) { var str = '' str += '<li>' str += ' <span class="created_at">'+ message.timestamp +'</span>' str += ' '+ message.content str += '</li>' $('#chat').append(str) })
  • 17. Demo
  • 19. Events • handshake • subscribe • unsubscribe • publish • disconnect
  • 20. var Faye = require('faye') var server = new Faye.NodeAdapter({ mount: '/faye' }) server.listen(8000) server.bind('handshake', function(client_id) { console.log("[handshake] - client: '"+ client_id +"'") }) server.bind('subscribe', function(client_id, channel) { console.log("[subscribe] - client: '"+ client_id +"', channel: '"+ channel +"'") }) server.bind('unsubscribe', function(client_id, channel) { console.log("[unsubscribe] - client: '"+ client_id +"', channel: '"+ channel +"'") }) server.bind('publish', function(client_id, channel, data) { console.log("[publish] - client: '"+ client_id +"', channel: '"+ channel +"'") console.log("[publish] - data:") console.log(data) }) server.bind('disconnect', function(client_id) { console.log("[disconnect] - client: '"+ client_id +"'") })
  • 21. require 'faye' require 'logger' Faye::WebSocket.load_adapter('thin') faye = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25) log = Logger.new(STDOUT) log.level = Logger::INFO faye.bind(:handshake) do |client_id| log.info("[handshake] - client: '#{client_id}'") end faye.bind(:subscribe) do |client_id,channel| log.info("[subscribe] - client: '#{client_id}', channel: '#{channel}'") end faye.bind(:unsubscribe) do |client_id,channel| log.info("[unsubscribe] - client: '#{client_id}', channel: '#{channel}'") end faye.bind(:publish) do |client_id,channel,data| log.info("[publish] - client: '#{client_id}', channel: '#{channel}', data: '# {data.inspect}'") end faye.bind(:disconnect) do |client_id| log.info("[disconnect] - client: '#{client_id}'") end run faye
  • 22. Extensions • Override default behaviour... • incoming() • outgoing()
  • 23. Engines • Change the back-end... • faye-redis
  • 24. var faye = require('faye') var faye_redis = require('faye-redis') var server = new faye.NodeAdapter({ mount: '/faye', timeout: 25, engine: { type: faye_redis, host: 'localhost', port: 6379 } }) server.listen(8000)
  • 25. require 'faye' require 'faye-redis' server = Faye::RackAdapter.new( :mount => '/faye', :timeout => 25, :engine => { :type => Faye::Redis, :host => 'localhost', :port => 6379 } ) server.listen(8000)