title: Amazon Sqs Queue abstraction
body: <p>We have started working with Amazon SQS and implemented a queue abstraction with the help of snippets provided in <a href="https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/examples-sqs-messages.html" rel="nofollow noreferrer">documentation</a>.</p>
  
  <p>While I was discovering the AWS SDK source on Github, I've found a class called <a href="https://github.com/aws/aws-sdk-cpp/blob/master/aws-cpp-sdk-queues/source/sqs/SQSQueue.cpp" rel="nofollow noreferrer">SQSQueue</a> which is %80 same with our own implementation.</p>
  
  <p>1 - Is it documented anywhere ? (except from the auto generated Doxygen output)</p>
  
  <p>2 - The only defective part of the provided implementation is that it waits until poll period gets expired even though the queue is not empty. In other words, if there are more than one element in the queue, it should continue receiving messages without waiting the poll period.</p>
  
  <p>The only solution that I can think of is implementing the receive callback in the following way :</p>
  
  <pre><code>void messageReceived(const Aws::Queues::Queue&lt;Aws::SQS::Model::Message&gt;* queue, const Aws::SQS::Model::Message&amp; message, bool&amp; deleteMessage)
  {
      /* Process message */
      deleteMessage = true;
  
      auto newMessage = queue-&gt;Top();
      if (newMessage.GetBody().empty() == false) {
          bool deleteNewMessage = false;
          messageReceived(queue, newMessage, deleteNewMessage);
  
          if(deleteNewMessage) {
              auto nonConstQueue = const_cast&lt;Aws::Queues::Queue&lt;Aws::SQS::Model::Message&gt;*&gt;(queue);
              nonConstQueue-&gt;Delete(newMessage);
          }
      }
  
  }
  </code></pre>
  
  <p>However,</p>
  
  <p>a) I hate const_cast.</p>
  
  <p>b) Recursive methods make me scared.</p>
  
  <p>Is there any other solution ?</p>