2

I have a JRuby/Rails app using Rack::FiberPool and EventMachine. And I have some event-based action controller:

class TwitterController < ApllicationController
  def tweets
    fiber = Fiber.current
    tweets = nil 

    EventMachine.next_tick do  
      http = EM::HttpRequest.new("http://search.twitter.com/search?q=rails+3&format=json").get
      http.callback do
        tweets = JSON.parse(http.response)
        fiber.resume
      end

      http.errback do
        puts "request failed"
        fiber.resume
      end     
    end

    Fiber.yield

    render :json => tweets
  end
end

It works fine when I run manually with Thin server:

rails s thin

But it will not work when I deploy to Tomcat. Is there anyway to use EventMachine in Tomcat?

Thanks.

Blue Smith
  • 8,580
  • 2
  • 28
  • 33
  • What do you mean 'will not work'? Can you post the log or describe what is going on, please? – Sully Jan 16 '13 at 20:39
  • If this is all your code, you might need to start an EventMachine reactor yourself. Does your code run on WebRick? (i.e. rails s without the thin argument) – Martijn Jan 17 '13 at 15:31
  • Thanks for your concern. I successfully applied [this tip](http://stackoverflow.com/a/8014413/1405852) with WebRick, but it cannot work when I deploy to Tomcat, because basically, EM cannot start in that environment. – Blue Smith Jan 20 '13 at 17:56

0 Answers0