I was wondering if it's possible to make a rails app subscribe to some
faye channel. Messages on this channel will contain information that
I would use to operate on rails models. I was thinking of using a
faye server extension that will publish a message to this rails
channel when it sees a /meta/subscribe message. Then the subscriber
inside of rails will use some data model to record this subscription.
I was thinking of starting a faye client which subscribes to this
channel when rails app starts up. I would make it an initializer,
e.g.
in config/initializers/faye_client.rb:
$client = Faye::Client.new('
http://localhost:9292/faye')
client.subscribe('/railsapp') do |message|
RailsAppModel.create(message.ext.user_id)
end
In faye's documentation, it says that a faye client needs to run
inside of eventmachine. That means I cannot really do what I wrote
above, but I would need to put the code inside of
EM.run do
#code goes here
end
But then the initializer will go into a loop and never returns, in
which case the rails app will not run. Could someone help with this
problem of making a rails app listen on faye channels?
Actually, I'm not even sure if I can publish messages inside of a faye
server extension. My problem really is how should a faye server
communicate with a rails application.
Thank you for your help.