Beispiel #1
0
int
testMessages(SQSConnection* lSQSCon)
{
  {
    try {
    	// create queue
      CreateQueueResponsePtr lCreateQueue = lSQSCon->createQueue("aQueue");
      std::string lAQueueURL = lCreateQueue->getQueueUrl();
      std::cout << "Bucket created successfully. QueueUrl: " << lAQueueURL << std::endl;

      // send message
      SendMessageResponsePtr lSendResponse = lSQSCon->sendMessage(lAQueueURL, "my cool body");
      std::string lMessageId = lSendResponse->getMessageId();
      if (lMessageId == "") {
      	std::cout << "Emtpy message ID" << std::cout;
      	return 1;
      }
      std::cout << "Message sent. ID: " << lMessageId << std::endl;

      // receive message
      ReceiveMessageResponsePtr lReceiveResponse = lSQSCon->receiveMessage(lAQueueURL,
      		1, -1);
      ReceiveMessageResponse::Message lMessage;
      int lCount = 0;
      lReceiveResponse->open();
      while (lReceiveResponse->next(lMessage)) {
      	std::cout << "Message received. ID: " << lMessage.message_id << std::endl;
      	std::cout << "Message body: ";
      	std::cout.write(lMessage.message_body, lMessage.message_size);
      	std::cout << std::endl;
      	lCount++;
      }
      lReceiveResponse->close();
      if (lCount != 1) {
      	std::cout << "Wrong number of messages (exp. 1): " << lCount << std::endl;
      	return 1;
      }

      // delete message
      DeleteMessageResponsePtr lDeleteResponse = lSQSCon->deleteMessage(lAQueueURL,
      		lMessage.receipt_handle);
      std::cout << "Message with ID " << lMessage.message_id << " has been deleted" << std::endl;

      // delete queue
			DeleteQueueResponsePtr lDeleteQueue = lSQSCon->deleteQueue(lAQueueURL);
      std::cout << "Queue " << lAQueueURL << " has been deleted" << std::endl;

    } catch (CreateBucketException& e) {
      std::cerr << "Couldn't create bucket" << std::endl;
      std::cerr << e.what() << std::endl;
      return 1;
    }
  }
  return 0;
}
Beispiel #2
0
bool createQueue (SQSConnectionPtr aSQS, std::string aQueueName, int aVisibilityTimeout) {
    try {
        CreateQueueResponsePtr lRes = aSQS->createQueue (aQueueName, aVisibilityTimeout);
        std::cout << "queue created successfully" << std::endl;
        std::cout << "   url: "  << lRes->getQueueUrl() << std::endl;
    } catch (CreateBucketException &e) {
        std::cerr << e.what() << std::endl;
        return false;
    }
    return true;
}
Beispiel #3
0
int
testQueues(SQSConnection* lSQSCon)
{
  {
    try {
    	// test create queue
      CreateQueueResponsePtr lCreateQueue = lSQSCon->createQueue("aQueue");
      std::string lAQueueURL = lCreateQueue->getQueueUrl();
      std::cout << "Bucket created successfully. QueueUrl: " << lAQueueURL << std::endl;
      lCreateQueue = lSQSCon->createQueue("bQueue");
      std::string lBQueueURL = lCreateQueue->getQueueUrl();
      std::cout << "Bucket created successfully. QueueUrl: " << lBQueueURL << std::endl;

      // test list queues without prefix
      ListQueuesResponsePtr lListQueues = lSQSCon->listQueues();
      lListQueues->open();
      std::string lName;
      int lCount = 0;
      while (lListQueues->next(lName)) {
        std::cout << "Queue Name: " << lName << std::endl;
        lCount++;
      }
      lListQueues->close();
      if (lCount != 2) {
      	std::cout << "Wrong number of queues (exp. 2): " << lCount << std::endl;
      	return 1;
      }

      // test list queues with prefix
      lCount = 0;
      lListQueues = lSQSCon->listQueues("a");
			lListQueues->open();
			while (lListQueues->next(lName)) {
				std::cout << "Queue Name: " << lName << std::endl;
				lCount++;
			}
			lListQueues->close();
			if (lCount != 1) {
      	std::cout << "Wrong number of queues (exp. 1): " << lCount << std::endl;
				return 1;
			}

			// test delete queue
			DeleteQueueResponsePtr lDeleteQueue = lSQSCon->deleteQueue(lAQueueURL);
      std::cout << "Queue " << lAQueueURL << " has been deleted" << std::endl;
			lDeleteQueue = lSQSCon->deleteQueue(lBQueueURL);
      std::cout << "Queue " << lBQueueURL << " has been deleted" << std::endl;

      // test list queues (should be empty now)
      lCount = 0;
      lListQueues = lSQSCon->listQueues();
			lListQueues->open();
			while (lListQueues->next(lName)) {
				std::cout << "Queue Name: " << lName << std::endl;
				lCount++;
			}
			lListQueues->close();
			if (lCount != 0) {
      	std::cout << "Wrong number of queues (exp. 0): " << lCount << std::endl;
				return 1;
			}

    } catch (CreateBucketException& e) {
      std::cerr << "Couldn't create bucket" << std::endl;
      std::cerr << e.what() << std::endl;
      return 1;
    }
  }
  return 0;
}