README.md in faye-rails-2.0.0 vs README.md in faye-rails-2.0.1

- old
+ new

@@ -3,57 +3,55 @@ faye-rails is a Ruby gem which handles embedding Faye's rack-based server into the rails stack and providing it with access to controllers and views based on bindings and observers. [![Build Status](https://travis-ci.org/jamesotron/faye-rails.png?branch=master)](https://travis-ci.org/jamesotron/faye-rails) [![Dependency Status](https://gemnasium.com/jamesotron/faye-rails.png)](https://gemnasium.com/jamesotron/faye-rails) [![Code Climate](https://codeclimate.com/github/jamesotron/faye-rails.png)](https://codeclimate.com/github/jamesotron/faye-rails) -[![jcog:secure](http://sociable.co.nz/downloads/images/jcog_secure.png)](http://sociable.co.nz/blog/2013/04/18/offical-jcog-secure-badge-for-all-your-software-security-needs/) A *very* small demonstration app is available for your perusal [on Heroku](http://faye-rails-demo.herokuapp.com/). The source is [here on Github](https://github.com/jamesotron/faye-rails-demo). +# Heroku Add-on + +If you're planning on running Faye on Heroku you're probably going to have a bad time. Take a look at [MessageRocket](https://messagerocket.co/) as an alternative, and help support the author to maintain more great open source projects. + # Embedded server -Due to the limitations of most Rack-based web servers available Faye can only be run on Thin, however if you are using thin, then you can add as many Faye servers as you want to the Rails router like so: +Due to the limitations of most Rack-based web servers available Faye can only be run on Thin, however if you are using thin, then you can add as many Faye servers as you want to the Rails middleware stack like so: ```ruby -App::Application.routes.draw do - faye_server '/faye', :timeout => 25 -end +# application.rb +config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25 ``` You can also pass a block to `faye_server` which will be executed in the context of the Faye server, thus you can call any methods on `Faye::RackAdapter` from within the block: ```ruby -App::Application.routes.draw do - faye_server '/faye', :timeout => 25 do - class MockExtension - def incoming(message, callback) - callback.call(message) - end +config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25 do + # can be defined anywhere, like app/faye_extensions/mock_extension.rb + class MockExtension + def incoming(message, callback) + callback.call(message) end - add_extension(MockExtension.new) end + + add_extension(MockExtension.new) end ``` If you really want to, you can ask Faye to start it's own listening Thin server on an arbitrary port: ```ruby -App::Application.routes.draw do - faye_server '/faye', :timeout => 25 do - listen(9292) - end +config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25 do + listen(9292) end ``` You can also do some rudimentary routing using the map method: ```ruby -App::Application.routes.draw do - faye_server '/faye', :timeout => 25 do - map '/widgets/**' => WidgetsController - map :default => :block - end +config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25 do + map '/widgets/**' => WidgetsController + map :default => :block end ``` You can find more details on the #map method in the [rdoc](http://rubydoc.info/github/jamesotron/faye-rails/master/FayeRails/RackAdapter) @@ -140,24 +138,22 @@ # Non-server environments Often you'll find yourself running the Rails environment without the server running - eg when doing background job processing, or running the console. If you have any actions which use Faye then you'll need to make sure that you have the EventMachine reactor running. The easiest solution to this is to create an initialiser in `config/initializers` which calls `Faye.ensure_reactor_running!`. For workers in production you probably also want to make sure that you are using the Redis engine for Faye to ensure that multiple server instances see the same data. ```ruby -App::Application.routes.draw do - faye_server '/faye', timeout: 25, engine: {type: Faye::Redis, host: 'localhost'} do - map '/announce/**' => SomeController - end +config.middleware.use FayeRails::Middleware, mount: '/faye', engine: {type: Faye::Redis, host: 'localhost'}, :timeout => 25 do + map '/announce/**' => SomeController end ``` +See more details in [this issue on GitHub](https://github.com/jamesotron/faye-rails/issues/26). + # Running on Phusion Passenger If you want to run faye-rails on passenger, make sure you are using passenger 4.0 standalone or passenger 4.0 on nginx 1.4+ for nginx with websocket support. Passenger on apache is not supported. Because passenger uses a multi-process model, you must use the faye redis backend. Add `gem 'faye-redis'` to your Gemfile and configure your routes like this: ```ruby -App::Application.routes.draw do - faye_server '/faye', timeout: 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'} -end +config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'} ``` # Thanks. Thanks to James Coglan for the excellent Faye Bayeux implementetation and great support for Faye users.