title: RabbitMQ with EventMachine and Rails
body: <p>we are currently planning a rails 3.2.2 application where we use RabbitMQ. We would like to run several kind of workers (and several instances of a worker) to process messages from different queues. The workers are written in ruby and are laying in the lib directory of the rails app.</p>
  
  <p>Some of the workers needs the rails framework (active record, active model...) and some of them don't. The first worker should be called every minute to check if updates are available. The other workers should process the messages from their queues when messages (which are send by the first worker) are present and do some (time consuming) stuff with it.</p>
  
  <p>So far, so good. My problem is, that I only have little experiences with messaging systems like RabbitMQ and no experiences with the rails interaction between them. So I'm wondering what the best practices are to get the two playing with each other. Here are my requirements again:</p>
  
  <ul>
  <li>Rails 3.2.2 app</li>
  <li>RabbitMQ</li>
  <li>Several kind of workers</li>
  <li>Several instances of one worker</li>
  <li>Control the amount of workers out of rails</li>
  <li>Workers are doing time consuming tasks, so they have to be async</li>
  <li>Only a few workers needs the rails framework. The others are just ruby files with some dependencies like Net or File</li>
  </ul>
  
  <p>I was looking for some solution and came up with two possibilities:</p>
  
  <p><strong>Using amqp with EventMachine in a new thread</strong></p>
  
  <p>Of course, I don't want my rails app to be blocked when a new worker is created. The worker should run in another thread and do its work asynchronously. And furthermore, it should not start a new instance of my rails application. It should only require the things the worker needs.</p>
  
  <p>But in some articles they say that there are some issues with Passenger. And another fact that I don't like is, that we are using webbrick for development and we ought to include workarounds for that too. It would be possible to switch to another webserver like thin, but I don't have any experience with that either.</p>
  
  <p><strong>Using some kind of daemonizing</strong></p>
  
  <p>Maybe its possible to run workers as a daemon, but I don't know how much overhead this would come up with, or how I can control the amount of workers.</p>
  
  <p>Hope someone can advise a good solution for that (and I hope I made myself clear ;)</p>