How do you spawn an EventMachine “inside” a Rails app?

前端 未结 8 2094
星月不相逢
星月不相逢 2020-12-13 14:54

I\'ve got a Rails application, and am looking to add some sort of WebSocket support to it. From various googling, it appears that the best Ruby based WebSocket solution is

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 15:27

    You probably shouldn't use EM any more if you can help it, it seems to no longer be maintained - if you encounter a bug - you're on your own.

    Most of the answers above don't work in JRuby due to https://github.com/eventmachine/eventmachine/issues/479 - namely the pattern:

    Thread.new{ EM.run }
    

    used by EM::Synchrony and various answers found around the internet (such as EventMachine and Ruby Threads - what's really going on here?) are broken under JRuby eventmachine implementation (fibers are threads in jruby and there's currently no roadmap on when this will change).

    JRuby messaging options would be

    1. deploy with TorqueBox (which comes bundled with HornetQ), http://torquebox.org/news/2011/08/15/websockets-stomp-and-torquebox/, impressive and enterprisey but not really elegant unless you're coming from a Java background
    2. newer versions of Faye should work with JRuby, Faye in jruby on rails
    3. note for the future, keep an eye on the celluloid community, some interesting distributed solutions are coming from there https://github.com/celluloid/reel/wiki/WebSockets, https://github.com/celluloid/dcell
    4. ?

提交回复
热议问题