title: How to send and receive domain objects with rabbitMQ plugin and grails
body: <p>I've went over the excellent documentation for the rabbitMQ plugin. However, I am still confused about a few things. </p>
  
  <p><strong>Scenario</strong></p>
  
  <p>My application will take a file upload from the user, do various things to the file and accordingly set certain properties on the domain object. Some of this work can be labor intensive so I am using a queue. I envision requests being queued and the consumer picking up the requests from the queue and consuming them. </p>
  
  <p><strong>Questions</strong></p>
  
  <p>I want to store a domain object in the queue. I do this by: <code>rabbitSend 'myqueue', colorObj</code>. <code>colorObj</code>is an object of domain class <code>Color</code>
  However, in the <code>ColorService</code> <code>handleMessage(...)</code> When I fetch the item from the queue, the item is not of type <code>Color</code>. Please note that on the rabbitMQ dashboard I can see the items being inserted in the queue, so my queue initiation in <code>config.groovy</code> is fine (I am using <code>amq.direct</code>)</p>
  
  <ul>
  <li>How can I send and fetch a domain object from the queue?</li>
  <li>From the behavior I've seen thus far, the <code>handleMessage</code> does not need to be instantiated. Even if I don't call the <code>ColorService</code> it still executes <code>handleMessage</code> by itself. Is that a normal behavior?</li>
  </ul>
  
  <p>Below is the code:</p>
  
  <p><em>controller</em></p>
  
  <pre><code>Color colorObj = colorService.newRequest(params, request.getFile('color.filename')
  if (colorObj.validate)
    rabbitSend 'myqueue', colorObj
  ...
  </code></pre>
  
  <p><em>service</em></p>
  
  <pre><code>class ColorService {
    static rabbitQueue = 'myqueue'
  
    void handleMessage(message) {
      println "came in message: " + message instanceof Color //this prints false
    }
  }
  </code></pre>