Creating a Queue

The first step in using Amazon SQS is to create one or more queues. The following sample code snippets demonstrate creation of a queue named MyQueue.

Java

To run the sample

  1. Open CreateQueueSample.java.

  2. Locate the following lines.

    CreateQueueRequest request = new CreateQueueRequest();
    
    // @TODO: set request parameters here
    
    // invokeCreateQueue(service, request);
  3. Replace the lines with the following new lines of code.

    CreateQueueRequest request = new CreateQueueRequest();
    request.setQueueName("MyQueue");
    invokeCreateQueue(service, request);
  4. Compile and run the sample.

    The MyQueue queue is created. The sample prints the queue URL for the queue and the request ID that Amazon SQS assigned to your request.

[Note]Note

When you design your own application, we recommend you include a check for the SimpleQueueService.QueueDeletedRecently error, which SQS returns if you try to create a new queue with the name of a queue you've just deleted. You must wait 60 seconds after deleting a queue before creating a new queue with the same name.

C#

To run the sample

  1. Open AmazonSQSSamples.cs.

  2. Locate the following lines.

    // CreateQueueRequest request = new CreateQueueRequest();
    // @TODO: set request parameters here
    // CreateQueueSample.InvokeCreateQueue(service, request);
  3. Replace the lines with the following new lines of code.

    CreateQueueRequest request = new CreateQueueRequest();
    request.QueueName = "MyQueue";
    CreateQueueSample.InvokeCreateQueue(service, request);
  4. Run the sample.

    The MyQueue queue is created. The sample prints the queue URL for the queue and the request ID that Amazon SQS assigned to your request.

[Note]Note

When you design your own application, we recommend you include a check for the SimpleQueueService.QueueDeletedRecently error, which SQS returns if you try to create a new queue with the name of a queue you've just deleted. You must wait 60 seconds after deleting a queue before creating a new queue with the same name.

Perl

To run the sample

  1. Open CreateQueueSample.pl.

  2. Locate the following line.

    # invokeCreateQueue($service, $request);
  3. Replace the line with the following new lines of code.

    my $request = Amazon::SQS::Model::CreateQueueRequest->new({
    QueueName => "MyQueue"
    });
    invokeCreateQueue($service, $request);
  4. Run the sample.

    The MyQueue queue is created. The sample prints the queue URL for the queue and the request ID that Amazon SQS assigned to your request.

[Note]Note

When you design your own application, we recommend you include a check for the SimpleQueueService.QueueDeletedRecently error, which SQS returns if you try to create a new queue with the name of a queue you've just deleted. You must wait 60 seconds after deleting a queue before creating a new queue with the same name.

PHP5

To run the sample

  1. Open CreateQueueSample.php.

  2. Locate the following line.

    // invokeCreateQueue($service, $request);
  3. Replace the line with the following new lines of code.

    require_once ('Amazon/SQS/Model/CreateQueueRequest.php'); 
    $request = new Amazon_SQS_Model_CreateQueueRequest();
    $request->setQueueName('MyQueue');
    invokeCreateQueue($service, $request);
  4. Run the sample.

    The MyQueue queue is created. The sample prints the queue URL for the queue and the request ID that Amazon SQS assigned to your request.

[Note]Note

When you design your own application, we recommend you include a check for the SimpleQueueService.QueueDeletedRecently error, which SQS returns if you try to create a new queue with the name of a queue you've just deleted. You must wait 60 seconds after deleting a queue before creating a new queue with the same name.

VB.NET

To run the sample

  1. Open AmazonSQSSamples.vb.

  2. Locate the following lines.

    ' Dim request As New CreateQueueRequest()
    ' @TODO: set request parameters here
    ' CreateQueueSample.InvokeCreateQueue(service, request)
  3. Replace the lines with the following new lines of code.

    Dim request As New CreateQueueRequest()
    request.QueueName = "MyQueue"
    CreateQueueSample.InvokeCreateQueue(service, request)
  4. Run the sample.

    The MyQueue queue is created. The sample prints the queue URL for the queue and the request ID that Amazon SQS assigned to your request.

[Note]Note

When you design your own application, we recommend you include a check for the SimpleQueueService.QueueDeletedRecently error, which SQS returns if you try to create a new queue with the name of a queue you've just deleted. You must wait 60 seconds after deleting a queue before creating a new queue with the same name.

Scratchpad

To run the sample

  1. In the scratchpad, select CreateQueue from the Explore API list box.

  2. Enter MyQueue in the Queue Name field, and leave the Default Visibility Timeout field blank.

  3. Select one of the following:

    • To invoke the request, click Invoke Request. Amazon SQS returns a response.

    • To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser. Amazon SQS returns a response.

    • To view the string to sign, click Display String to Sign.