Reputation: 664
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
Upvotes: 2
Views: 2966
Reputation: 2677
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)
Upvotes: 4