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

2
  • Are you looking for message queuing tool?
    – TM.
    Jul 16, 2013 at 15:43
  • If you mean something like ActiveMQ: No. Rather something like long polling, websockets etc... Jul 16, 2013 at 20:14

1 Answer 1

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)

2
  • Unfortunately the project uses rails 3.2 Jul 18, 2013 at 6:03
  • I updated my answer with a couple of links, you may try to play with that approach Jul 18, 2013 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.