Amazon SQS Sample in Java

Sample Code & Libraries>Java>Amazon SQS Sample in Java
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

This code provides a basic sample for how to use Amazon SQS with Java.

Details

Submitted By: B&Z
AWS Products Used: Amazon SQS
Language(s): Java
License: Apache License 2.0
Created On: January 21, 2008 11:44 PM GMT
Last Updated: April 6, 2010 8:33 PM GMT
Download
Now Available: AWS SDK for Java
As of March 2010, this library has been deprecated and will no longer be updated. We recommend using the new AWS SDK for Java, where you'll continue to get new feature updates and bug fixes. To learn more about the AWS SDK for Java, and for support with migration, see http://aws.amazon.com/sdkforjava.

About This Sample

  • A Java sample to demonstrate creating a queue, sending messages, receiving messages, and deleting messages.
  • Based on the 2008-01-01 API version.

Prerequisites

  • You must have a valid Amazon Web Services developer account.
  • You must be signed up to use Amazon SQS.
  • You must install Java 1.6 or newer:
    1. Follow the instructions on the Sun Java web site to install the JDK 1.6 (for the instructions, see http://java.sun.com/javase/downloads/index.jsp).
    2. Set your JAVA_HOME environment variable to point to your JDK installation location.
    3. To verify you have the correct JDK installed, open a console window and type the following:
      java -version

      The response should be similar to the following:
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment, build 1.6.0_02-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)
      
  • You must install Ant.
    1. Follow the instructions on the Apache Ant web site to install Ant (for the instructions, see http://ant.apache.org/manual/index.html).
    2. Set your ANT_HOME environment variable to point to your Ant installation location.
    3. To verify you have the correct version of Ant installed, open a console window and type the following:
      ant -version

      The response should be similar to the following:
      Apache Ant version 1.6.5 compiled on June 2 2005

Running the Sample

  1. Go to the /SQSJavaSample/SQSSample/src/com/amazonaws/sqs directory of the sample code package and open the SampleDriver.java file in a text editor.
  2. Locate the following two lines of code:
    static public String awsAccessKeyId = "";
    static public String awsSecretAccessKey = ""; 
  3. Insert your Access Key ID and Secret Access Key between the quotation marks, as in the following example:
    static public String awsAccessKeyId = "Your Access Key ID";
    static public String awsSecretAccessKey = "Your Secret Access Key";
  4. Save the file.
  5. At a command prompt, go to the top directory of the sample (it contains build.xml file) and type the following:
    ant run
    The example compiles and runs.

Comments

not without hassles
The setup information is misleading: The source may be Java 1.5, but you actually need the 1.6 version of the JDK to compile and link the thing; otherwise you get warnings about missing javax.xml.stream.XMLStreamReader classes and the like. On the plus side, it is the latest API [Jan 2008].
Robert C. Kahlert on February 11, 2008 11:15 PM GMT
We are temporarily not accepting new comments.
©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.