Amazon Simple Queue Service
Getting Started Guide (API Version 2011-10-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Sending a Message

Now that you've confirmed your queue exists in the Amazon SQS system, you can send a message to the queue. The following code snippets demonstrate how to send the message This is my message text. to your MyQueue queue.

AWS Management Console

To send a message

  1. In the AWS Management Console select a queue.

    AWS Management Console queue list: select queue
  2. Select Send a Message from the Queue Actions drop-down list.

    [Note]Note

    The Queue Actions drop-down list is available only if a queue is selected.

    AWS Management Console send SQS message
  3. In the Send a Message to MyQueue dialog box, enter This is my message text. and click Send Message.

    AWS Management Console send SQS message dialog
  4. In the Send a Message to MyQueue confirmation box click Close.

    AWS Management Console send SQS message dialog confirmation

Scratchpad

To run the sample

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

  2. Enter the queue URL (which you received when you created the queue) in the Queue URL field.

  3. Enter This is my message text. in the Message Body field.

  4. 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.

Java

To run the sample

  1. Open SimpleQueueServiceSample.java.

    The following section of the code sends a message to your queue:

    // Send a message
    System.out.println("Sending a message to MyQueue.\n");
    sqs.sendMessage(new SendMessageRequest()
        .withQueueUrl(myQueueUrl)
        .withMessageBody("This is my message text."));
  2. Compile and run the sample.

    The message This is my message text. is sent to the queue. The response includes the following items:

    • The message ID Amazon SQS assigns to the message

    • An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)

    • The request ID that Amazon SQS assigned to your request

C#

To run the sample

  1. Open Program.cs.

    The following section of the code sends a message to your queue:

    //Sending a message
    Console.WriteLine("Sending a message to MyQueue.\n");
    SendMessageRequest sendMessageRequest = new SendMessageRequest();
    sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation
    sendMessageRequest.MessageBody = "This is my message text.";
    sqs.SendMessage(sendMessageRequest);
  2. Run the sample.

    The message This is my message text. is sent to the queue. The response includes the following items:

    • The message ID Amazon SQS assigns to the message

    • An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)

    • The request ID that Amazon SQS assigned to your request

Perl

To run the sample

  1. Open SendMessageSample.pl.

  2. Locate the following line.

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

    my $request = Amazon::SQS::Model::SendMessageRequest->new({
    QueueUrl => "queue URL you received from CreateQueue call",
    MessageBody => "This is my message text."
    });
    invokeSendMessage($service, $request);
  4. Run the sample.

    The message This is my message text. is sent to the queue. The response includes the following items:

    • The message ID Amazon SQS assigns to the message

    • An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)

    • The request ID that Amazon SQS assigned to your request

PHP5

To run the sample

  1. Open SendMessageSample.php.

  2. Locate the following line.

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

    require_once ('Amazon/SQS/Model/SendMessageRequest.php');
    $request = new Amazon_SQS_Model_SendMessageRequest();
    $request->setQueueUrl('queue URL you received from CreateQueue call');
    $request->setMessageBody('This is my message text.');
    invokeSendMessage($service, $request);
  4. Run the sample.

    The message This is my message text. is sent to the queue. The response includes the following items:

    • The message ID Amazon SQS assigns to the message

    • An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)

    • The request ID that Amazon SQS assigned to your request