[rabbitmq-discuss] Ruby Gem with Unicorn server

Michael Klishin michael.s.klishin at gmail.com
Tue Jan 17 18:10:26 GMT 2012


> Is this all that is required?

Yes. In 0.9.0 (possibly in 0.8.4 as well) there is a helper that reads config/amqp.yml similarly to config/database.yml:

  require "amqp/utilities/event_loop_helper"
  require "amqp/integration/rails"

  # this helper detects what app server (if any) is being used and starts EventMachine reactor in a separate
  # thread or just uses .next_tick (for example, with Thin).

  # reads config/amqp.yml, takes environment-specific key out of it (e.g. :development) and
  # merges whatever you pass to .start with it.
  AMQP::Integration::Rails.start do |connection|
    puts "Connected to AMQP broker"
    # this is just an accessor for 1 channel. It has no special properties, just a placeholder for
    # applications that only need one channel
    AMQP.channel    = AMQP::Channel.new(connection)

I would like to try to make it detect Unicorn forking, that's why it is not not yet in the documentation: it may slightly change
for 1.0. Your suggestions about what you want it to do are very welcome.

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

Channels are typically opened when applications boot. Messages are published there just so that people can see messages flow. 
More on what role channels play: http://rubyamqp.info/articles/amqp_9_1_model_explained/#amqp_channels



More information about the rabbitmq-discuss mailing list