Developer Guide

Using Amazon SQS Queues

Amazon SQS offers standard as the default queue type. A standard queue enables you to have a nearly-unlimited number of transactions per second. Standard queues support at-least-once message delivery. However, occasionally more than one copy of a message might be delivered out of order. Standard queues provide best-effort ordering, which ensures that messages are generally delivered in the same order as they're sent.

You can use standard message queues in many scenarios, as long as your application can process messages that arrive more than once and out of order.

This code example demonstrates how to use queues by using these methods of the :code:AmazonSQSClient`class:

For more information about Amazon SQS messages, see How Amazon SQS Queues Work in the Amazon SQS Developer Guide.

List Your Queues

Create a ListQueuesRequest object containing the properties needed to list your queues, which by default is an empty object. Call the ListQueues method with the ListQueuesRequest as a parameter to retrieve the list of queues. The ListQueuesResponse returned by the call contains the URLs of all queues.

AmazonSQSClient client = new AmazonSQSClient(); ListQueuesResponse response = client.ListQueues(new ListQueuesRequest()); foreach (var queueUrl in response.QueueUrls) { Console.WriteLine(queueUrl); }

Get the URL for a Queue

Create a GetQueueUrlRequest object containing the properties needed to identify your queue, which must include the name of the queue whose URL you want. Call the GetQueueUrl method using the GetQueueUrlRequest object as a parameter. The call returns a GetQueueUrlResponse object containing the URL of the specified queue.

AmazonSQSClient client = new AmazonSQSClient(); var request = new GetQueueUrlRequest { QueueName = "SQS_QUEUE_NAME" }; GetQueueUrlResponse response = client.GetQueueUrl(request); Console.WriteLine("The SQS queue's URL is {1}", response.QueueUrl);

Delete a Queue

Create a DeleteQueueRequest object containing the URL of the queue you want to delete. Call the DeleteQueue method with the DeleteQueueRequest object as the parameter.

AmazonSQSClient client = new AmazonSQSClient(); var request = new DeleteQueueRequest { QueueUrl = "SQS_QUEUE_URL" }; client.DeleteQueue(request);