Menu
Amazon Simple Queue Service
Developer Guide

Tutorial: Sending a Message to an Amazon SQS Queue

After you create your queue, you can send a message to it. The following example demonstrates sending a message to an existing queue.

AWS Management Console

  1. Sign in to the AWS Management Console and open the Amazon SQS console at https://console.aws.amazon.com/sqs/.

  2. From the queue list, select a queue.

  3. From the Queue Actions drop-down list, select Send a Message.

    The Send a Message to QueueName dialog box is displayed.

    The following example shows the Message Group ID and Message Deduplication ID parameters specific to FIFO queues (content-based deduplication is disabled).

  4. To send a message to a FIFO queue, type the Message Body, the Message Group ID MyMessageGroupId1234567890, and the Message Deduplication ID MyMessageDeduplicationId1234567890, and then choose Send Message. For more information, see FIFO Queue Logic.

    Note

    The message group ID is always required. However, if content-based deduplication is enabled, the message deduplication ID is optional.

    Your message is sent and the Send a Message to QueueName dialog box is displayed, showing the attributes of the sent message.

    The following example shows the Sequence Number attribute specific to FIFO queues.

  5. Choose Close.

Java

Before you begin working with the example code, specify your AWS credentials. For more information, see Set Up AWS Credentials for Development in the AWS SDK for Java Developer Guide.

To send a message to a standard queue

  1. Copy the example program.

    The following section of the code sends the This is my message text. 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 example.

    The message 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, used to confirm that Amazon SQS received the message correctly (for more information, see RFC1321).

    • The request ID that Amazon SQS assigned to your request.

To send a message to a FIFO queue

  1. Copy the example program.

    The following section of the code sends the This is my message text. message to your queue:

    // Send a message
    System.out.println("Sending a message to MyFifoQueue.fifo.\n");
    SendMessageRequest sendMessageRequest = new SendMessageRequest(myQueueUrl, "This is my message text.");
    // You must provide a non-empty MessageGroupId when sending messages to a FIFO queue
    sendMessageRequest.setMessageGroupId("messageGroup1");
    // Uncomment the following to provide the MessageDeduplicationId
    //sendMessageRequest.setMessageDeduplicationId("1");
    SendMessageResult sendMessageResult = sqs.sendMessage(sendMessageRequest);
    String sequenceNumber = sendMessageResult.getSequenceNumber();
    String messageId = sendMessageResult.getMessageId();
    System.out.println("SendMessage succeed with messageId " + messageId + ", sequence number " + sequenceNumber + "\n");
  2. Compile and run the example.

    The message is sent to your queue.