After a little trial-by-fire, I’ve updated Qusion, my “AMQP made easy” library/plugin/what-have-you. Since I last wrote about it, I’ve added/addressed the following:
- The preferred way to run Qusion is now to call
Qusion.start; in Rails, this goes inside an after_initialize block in your environment.rb, like this:Rails::Initializer.run do |config| # stuff... config.after_initialize do Qusion.start end end - YAML-based configuration. Create a file named config/amqp.yml, fill in your details, and you’re good to go. Environments supported.
- Install Qusion as a Rails plugin, just like you’re used to:
script/plugin install git://github.com/danielsdeleo/qusion.git - Qusion plays nice with Workling
- Rails, from maybe 2.2-ish to about a week ago in edge, required thin when starting up via
script/serveras a workaround for some issue that’s long since been solved. This behavior tricked Qusion into behaving like it was running under thin when starting mongrel withscript/server. This has been fixed, and the behavior is verified in the specs. - More servers are experimentally supported: Evented Mongrel, WEBrick, SCGI. However, I primarily test Qusion with Passenger, Mongrel and Thin.
Now, it would be a dick move if I didn’t mention the the few gotchas you might run into with Qusion, and I’m not a big fan of dick moves. First of all, for non-evented servers, that is, everything other than Thin and Evented Mongrel, Qusion runs EventMachine in a thread. As MRI doesn’t run threads in parallel, this means that your app is running on a single core and switching contexts back and forth between the threads. This overhead may or may not be something you can tolerate. Secondly, if your broker (RabbitMQ) goes down, the AMQP library typically loses a few messages and silently attempts to reconnect. Any messages sent while there is no TCP connection to the broker are buffered, but during a graceful restart of RabbitMQ, there’s a few seconds of shutdown time. During the shutdown process RabbitMQ doesn’t accept messages but maintains the TCP connections with clients, meaning that any messages published during this time are silently dropped. The only way around this currently is to use the Bunny AMQP client which isn’t supported by Qusion right now. Brightbox’s Warren plugin might be for you if you want to configure your AMQP settings with YAML and use the Bunny client.
Gotchas aside, if you’re interested in using the AMQP gem with your web app and you want everything to just work on a variety of Ruby web servers, Qusion is your new best friend.