Há mais exemplos do AWS SDK disponíveis no repositório do GitHub Documento de Exemplos do AWS SDK
Usar GetQueueUrl com o AWS SDK ou a CLI
Os exemplos de código a seguir mostram como usar o GetQueueUrl.
- .NET
-
- SDK para .NET
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. using System; using System.Threading.Tasks; using Amazon.SQS; using Amazon.SQS.Model; public class GetQueueUrl { /// <summary> /// Initializes the Amazon SQS client object and then calls the /// GetQueueUrlAsync method to retrieve the URL of an Amazon SQS /// queue. /// </summary> public static async Task Main() { // If the Amazon SQS message queue is not in the same AWS Region as your // default user, you need to provide the AWS Region as a parameter to the // client constructor. var client = new AmazonSQSClient(); string queueName = "New-Example-Queue"; try { var response = await client.GetQueueUrlAsync(queueName); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"The URL for {queueName} is: {response.QueueUrl}"); } } catch (QueueDoesNotExistException ex) { Console.WriteLine(ex.Message); Console.WriteLine($"The queue {queueName} was not found."); } } }-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para .NET.
-
- C++
-
- SDK para C++
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; //! Get the URL for an Amazon Simple Queue Service (Amazon SQS) queue. /*! \param queueName: An Amazon SQS queue name. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SQS::getQueueUrl(const Aws::String &queueName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SQS::SQSClient sqsClient(clientConfiguration); Aws::SQS::Model::GetQueueUrlRequest request; request.SetQueueName(queueName); const Aws::SQS::Model::GetQueueUrlOutcome outcome = sqsClient.GetQueueUrl(request); if (outcome.IsSuccess()) { std::cout << "Queue " << queueName << " has url " << outcome.GetResult().GetQueueUrl() << std::endl; } else { std::cerr << "Error getting url for queue " << queueName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para C++.
-
- CLI
-
- AWS CLI
-
Como obter um URL de fila
Este exemplo obtém o URL da fila especificada.
Comando:
aws sqs get-queue-url --queue-nameMyQueueSaída:
{ "QueueUrl": "https://queue.amazonaws.com/80398EXAMPLE/MyQueue" }-
Consulte detalhes da API em GetQueueUrl
na Referência de comandos da AWS CLI.
-
- Java
-
- SDK para Java 2.x
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. GetQueueUrlResponse getQueueUrlResponse = sqsClient .getQueueUrl(GetQueueUrlRequest.builder().queueName(queueName).build()); return getQueueUrlResponse.queueUrl();-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK for Java 2.x.
-
- JavaScript
-
- SDK para JavaScript (v3)
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. Obtenha o URL para uma fila do Amazon SQS.
import { GetQueueUrlCommand, SQSClient } from "@aws-sdk/client-sqs"; const client = new SQSClient({}); const SQS_QUEUE_NAME = "test-queue"; export const main = async (queueName = SQS_QUEUE_NAME) => { const command = new GetQueueUrlCommand({ QueueName: queueName }); const response = await client.send(command); console.log(response); return response; };-
Para obter mais informações, consulte o Guia do desenvolvedor do AWS SDK para JavaScript.
-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para JavaScript.
-
- SDK para JavaScript (v2)
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. Obtenha o URL para uma fila do Amazon SQS.
// Load the AWS SDK for Node.js var AWS = require("aws-sdk"); // Set the region AWS.config.update({ region: "REGION" }); // Create an SQS service object var sqs = new AWS.SQS({ apiVersion: "2012-11-05" }); var params = { QueueName: "SQS_QUEUE_NAME", }; sqs.getQueueUrl(params, function (err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.QueueUrl); } });-
Para obter mais informações, consulte o Guia do desenvolvedor do AWS SDK para JavaScript.
-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para JavaScript.
-
- PowerShell
-
- Ferramentas para PowerShell V4
-
Exemplo 1: esse exemplo lista o URL da fila com o nome especificado.
Get-SQSQueueUrl -QueueName MyQueueSaída:
https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue-
Consulte detalhes da API em GetQueueUrl na Referência de cmdlet do Ferramentas da AWS para PowerShell (V4).
-
- Ferramentas para PowerShell V5
-
Exemplo 1: esse exemplo lista o URL da fila com o nome especificado.
Get-SQSQueueUrl -QueueName MyQueueSaída:
https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue-
Consulte detalhes da API em GetQueueUrl na Referência de cmdlet do Ferramentas da AWS para PowerShell (V5).
-
- Python
-
- SDK para Python (Boto3).
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. def get_queue(name): """ Gets an SQS queue by name. :param name: The name that was used to create the queue. :return: A Queue object. """ try: queue = sqs.get_queue_by_name(QueueName=name) logger.info("Got queue '%s' with URL=%s", name, queue.url) except ClientError as error: logger.exception("Couldn't get queue named %s.", name) raise error else: return queue-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para Python (Boto3).
-
- SAP ABAP
-
- SDK para SAP ABAP
-
nota
Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. TRY. oo_result = lo_sqs->getqueueurl( iv_queuename = iv_queue_name ). " oo_result is returned for testing purposes. " MESSAGE 'Queue URL retrieved.' TYPE 'I'. CATCH /aws1/cx_sqsqueuedoesnotexist. MESSAGE 'The requested queue does not exist.' TYPE 'E'. ENDTRY.-
Consulte detalhes da API em GetQueueUrl na Referência da API AWS SDK para SAP ABAP.
-