2

I search for a suitable way to build a pub/sub service between a Rails app and multiple Ruby clients.

I tried faye and faye-rails so far, but they are are not suitable, as messages getting queued up and not delivered until the client which is listening to the certain channel is restarted. Also I am not able to use a service like Pusher or PubNub.

Any recommendations?

Cheers Martin

Martin Röbert
  • 664
  • 8
  • 25

1 Answers1

4

For Rails 4 you may take a look at ActionController::Live. Won't that be suitable for your needs?

class MyController < ActionController::Base
  include ActionController::Live

  def stream
    response.headers['Content-Type'] = 'text/event-stream'
    100.times {
      response.stream.write "hello world\n"
      sleep 1
    }
  rescue IOError
    # client disconneted
  ensure
    response.stream.close
  end
end

For earlier Rails you may give a try to this approach: Ruby on Rails 3: Streaming data through Rails to client, Rails 3.2 streaming (the 2nd link is to notice the Last-Modified header)

Community
  • 1
  • 1
trushkevich
  • 2,657
  • 1
  • 28
  • 37