title: Getting result of a long running task with RabbitMQ
body: <p>I have a scenario where a client sends an http request to download a file. The file needs to be dynamically generated and typically takes 5-15 seconds. Therefore I am looking into a solution that splits this operation in 3 http requests.</p>
  
  <ol>
  <li>First request triggers the generation of the file. </li>
  <li>The client polls the server every 5 seconds to check if file is ready to download</li>
  <li>When the response to the poll request is positive, the client starts downloading the file </li>
  </ol>
  
  <p>To implement this I am looking into Message Queue solutions like RabbitMQ. They seem to provide a reliable framework to run long running tasks asynchronously. However after reading the <a href="http://www.rabbitmq.com/getstarted.html" rel="noreferrer">tutorials</a> on RabbitMQ, I am not sure how will I receive the result of the operation.</p>
  
  <p>Here is what I've in mind:</p>
  
  <p>A front end server receives requests from clients and it posts messages to RabbitMQ as required. This front end server will have 3 endpoints</p>
  
  <pre><code>/generate
  /poll
  /download
  </code></pre>
  
  <p>When client invokes <code>/generate</code> with a <code>GET</code> parameter say <code>request_uid=AAA</code>, the front end server will post a message to RabbitMQ with the request_uid in the payload. Any free worker will subsequently receive this message and start generating the file corresponding to <code>AAA</code>.</p>
  
  <p>Client will keep polling <code>/poll</code> with <code>request_uid=AAA</code> to check if task was complete.</p>
  
  <p>When task is complete client will call <code>/download</code> with <code>request_uid=AAA</code> expecting to download the file. </p>
  
  <p>The question is how will the <code>/poll</code> and <code>/download</code> handlers of the front end server will come to know about the status of the file generation job? How can RabbitMQ communicate the result of the task back to the producer. Or do I have to implement such mechanism outside RabbitMQ? (Consumer putting its results in a file <code>/var/completed/AAA</code>)</p>