title: Processing a Message Queue and Using Async
body: <p>I wrote a small test node app that loops and adds messages to a queue (azure storage queue), something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>var queueService = azure.createQueueService();
  var queueName = 'taskqueue';
  
  // other stuff like check if created
  
  // loop called after queue is confirmed
  
  for (i=0;i&lt;1000;i++){
    queueService.createMessage(queueName, "Hello world!", null, messageCreated);
  }
  
  // messageCreated does nothing at the moment, just logs to console
  </code></pre>
  
  <p>I'm trying to rewrite that to handle say 1 million create's using async to control the number of worker functions that are run in parallel.  This is a learning exercise more than anything.</p>
  
  <p><a href="https://github.com/caolan/async#queue" rel="nofollow">https://github.com/caolan/async#queue</a></p>
  
  <p>This is the basic setup for async's queue and I'm kind of at a loss as to what I need to change. I don't think the below will work:</p>
  
  <pre class="lang-js prettyprint-override"><code>var q = async.queue(function (task, callback) {
     queueService.createMessage(queueName, task.msg, null, messageCreated);
      callback();
  }, 100);
  
  
  // assign a callback.  Called when all the queues have been processed
  q.drain = function() {
      console.log('all items have been processed');
  }
  
  // add some items to the queue
  for(i=0;i&lt;1000000;i++) {
    q.push({msg: 'Hello World'}, function (err) {
      console.log('finished processing foo');
    });
      console.log('pushing: ' + i);
  }
  </code></pre>
  
  <p>I'm not quite grasping how to pull it all together with async.</p>