[rabbitmq-discuss] Ruby Gem with Unicorn server

Mark static.void.dev at gmail.com
Tue Jan 17 17:40:16 GMT 2012


Reading through 
http://rubydoc.info/github/ruby-amqp/amqp/master/file/docs/ConnectingToTheBroker.textile 
and I noticed when using the AMQP gem with Unicorn you must:

/"start the EventMachine reactor and AMQP connection after the master 
process forks workers"/

We've been using Unicorn for some time now so I'm aware of 
reestablishing connections after Unicorn forks, however I have some 
questions in regards to AMQP. Do I simply need to start up AMQP in a 
separate thread as in the example:

Thread.new  {  AMQP.start  }

Then in my controllers I would need to do everything inside a next_tick 
block?

EventMachine.next_tick  do
...
end


Is this all that is required? How come in the example we are connecting 
to a channel/queue in the after_fork hook? Is this for debugging purposes?

I also have one other question regarding EventMachine#next_tick. I've 
read that:

/"Everything scheduled using EM#next_tick will happen synchronously in 
the main thread.  Any long running tasks inside an EM#next_tick block 
will cause the entire program to block until complete. Typically a bad 
thing."

/Does this mean we don't gain anything by using EM in this fashion.. ie 
our attempt to use AMQP asynchronously is actually synchronous?

Thanks for the clarification!

- M




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120117/5e6f7e48/attachment.htm>


More information about the rabbitmq-discuss mailing list