SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
2023-05-05 14:44:00 -04:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* Before running this C++ code example, set up your development environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*
* For information on the structure of the code examples and how to build and run the examples, see
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html.
*
**/
2021-11-15 13:15:43 +00:00
// snippet-start:[sqs.cpp.list_queues.inc]
#include <aws/core/Aws.h>
#include <aws/sqs/SQSClient.h>
#include <aws/sqs/model/ListQueuesRequest.h>
#include <iostream>
// snippet-end:[sqs.cpp.list_queues.inc]
2023-05-05 14:44:00 -04:00
#include "sqs_samples.h"
2021-11-15 13:15:43 +00:00
2023-05-05 14:44:00 -04:00
// snippet-start:[cpp.example_code.sqs.ListQueues]
//! List the Amazon Simple Queue Service (Amazon SQS) queues within an AWS account.
/*!
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
2021-11-15 13:15:43 +00:00
*/
2023-05-05 14:44:00 -04:00
bool
AwsDoc::SQS::listQueues(const Aws::Client::ClientConfiguration &clientConfiguration) {
// snippet-start:[sqs.cpp.list_queues.code]
Aws::SQS::SQSClient sqsClient(clientConfiguration);
Aws::SQS::Model::ListQueuesRequest listQueuesRequest;
2023-05-05 14:44:00 -04:00
Aws::String nextToken; // Used for pagination.
Aws::Vector<Aws::String> allQueueUrls;
do {
if (!nextToken.empty()) {
listQueuesRequest.SetNextToken(nextToken);
2023-05-05 14:44:00 -04:00
}
const Aws::SQS::Model::ListQueuesOutcome outcome = sqsClient.ListQueues(
listQueuesRequest);
if (outcome.IsSuccess()) {
const Aws::Vector<Aws::String> &queueUrls = outcome.GetResult().GetQueueUrls();
allQueueUrls.insert(allQueueUrls.end(),
queueUrls.begin(),
queueUrls.end());
nextToken = outcome.GetResult().GetNextToken();
}
else {
std::cerr << "Error listing queues: " <<
outcome.GetError().GetMessage() << std::endl;
return false;
}
} while (!nextToken.empty());
std::cout << allQueueUrls.size() << " Amazon SQS queue(s) found." << std::endl;
for (const auto &iter: allQueueUrls) {
std::cout << " " << iter << std::endl;
2023-05-05 14:44:00 -04:00
}
// snippet-end:[sqs.cpp.list_queues.code]
return true;
2023-05-05 14:44:00 -04:00
}
// snippet-end:[cpp.example_code.sqs.ListQueues]
/*
*
* main function
*
* Usage: 'run_list_queues'
*
*/
#ifndef TESTING_BUILD
int main(int argc, char **argv) {
2021-11-15 13:15:43 +00:00
Aws::SDKOptions options;
Aws::InitAPI(options);
{
2023-05-05 14:44:00 -04:00
// snippet-start:[cpp.example_code.sqs.ListQueues.config]
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
// snippet-end:[cpp.example_code.sqs.ListQueues.config]
2021-11-15 13:15:43 +00:00
2023-05-05 14:44:00 -04:00
AwsDoc::SQS::listQueues(clientConfig);
2021-11-15 13:15:43 +00:00
}
Aws::ShutdownAPI(options);
}
2023-05-05 14:44:00 -04:00
#endif // TESTING_BUILD