Search code examples
c++amazon-sqsaws-sdk-cpp

Amazon Sqs Queue abstraction


We have started working with Amazon SQS and implemented a queue abstraction with the help of snippets provided in documentation.

While I was discovering the AWS SDK source on Github, I've found a class called SQSQueue which is %80 same with our own implementation.

1 - Is it documented anywhere ? (except from the auto generated Doxygen output)

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.

The only solution that I can think of is implementing the receive callback in the following way :

void messageReceived(const Aws::Queues::Queue<Aws::SQS::Model::Message>* queue, const Aws::SQS::Model::Message& message, bool& deleteMessage)
{
    /* Process message */
    deleteMessage = true;

    auto newMessage = queue->Top();
    if (newMessage.GetBody().empty() == false) {
        bool deleteNewMessage = false;
        messageReceived(queue, newMessage, deleteNewMessage);

        if(deleteNewMessage) {
            auto nonConstQueue = const_cast<Aws::Queues::Queue<Aws::SQS::Model::Message>*>(queue);
            nonConstQueue->Delete(newMessage);
        }
    }

}

However,

a) I hate const_cast.

b) Recursive methods make me scared.

Is there any other solution ?


Solution

  • To answer you first question, it's not documented anywhere. It's a high level utility of SQS written by AWS SDK for C++ team.

    Regard to 2nd question. I have seen similar PR on Github to modify the implementation to make it more effective. We will consider to merge it ASAP.