Resources



Sample Code and Libraries

Java Library for Amazon SQS

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

Java Library for Amazon SQS

Submitted By: Elena@AWS  
AWS Products Used: Amazon SQS
Language(s): Java
License: Apache License 2.0

About this Library

  • Based on the 2009-02-01 API version.

What's New?

  • 2009-04-14:
    • Fixed issue of invalid signature when queue name specified in mixed letter case
  • 2009-04-08:
    • Support for access control API
  • 2009-01-29:
    • Fix signature version 2 path encoding
  • 2009-01-05:
    • Url encoding fix (bug affected signature version 2 with values containing forward slash "/")
  • 2008-12-17:
    • Support for signature version 2, https endpoint
  • 2008-02-29:
    • Initial Release

Prerequisites

Reference Documentation

Package Content

Directory Overview
lib Binary distribution of library
src Source distribution of library.
third-party Binary distribution of library dependencies.

Quick Start

Library comes with code samples for each available service API. To get started with the library, follow these steps:
  1. Extract the amazon-queue-2009-02-01-java-library.zip file into a working directory.
  2. Add all sources under "src" directory to your compilation path.
  3. Add all jars files under "third-party/*" directory to your classpath
  4. Edit desired sample. For example: CreateQueueSample.java


    • Set AWS Access Key ID and AWS Secret Access Key
    • String accessKeyId = "Your Access Key ID";
      String secretAccessKey = "Your Secret Access Key";
                      


    • Set request parameters. For example, find following pre-generated snippet:
    • CreateQueueRequest request = new CreateQueueRequest();
      // @TODO: set request parameters here
      // invokeCreateQueue(service, request);
                      


    • And uncomment third line and add queue name to request:
    • CreateQueueRequest request = new CreateQueueRequest();
      request.setQueueName("MyQueue");
      invokeCreateQueue(service, request);
                      

  5. Compile and run CreateQueue. You should see the output similar to the following:


  6.     CreateQueueResponse
            CreateQueueResult
                QueueUrl
                    http://queue.amazonaws.com/MyQueue
            ResponseMetadata
                RequestId
                    95cdcb68-f46c-400b-8265-8c2de2a5c475
                

    Note, you may also see additional debugging output. To adjust level of debugging, modify log4j.properties available in the root of the source tree.

  7. Experiment with samples. When ready, add library binary distribution to your application classpath, and use it.

Happy coding!

Comments, Questions or Feedback

If you have any comments, questions or feedback on the library, please visit the Amazon Simple Queue Service discussion forums.


Related Documents
Type: Articles & Tutorials Introduction to AWS for Java Developers

Discussion

The 5 most recent discussion messages. View full discussion.

Mark Rebuck
RealName(TM)
Posts: 1
Registered: 6/11/08
Java Library for Amazon SQS
Posted: Jun 11, 2008 1:40 PM PDT
 
  Click to reply to this thread Reply

The contents box lists a "lib" directory, yet no such directory exists in the distribution I downloaded on 2008-06-11.  While working with source code is not hugely problematic, a cleaner distribution would make the Java bindings to SQS look a bit more fully baked.


D. Kavanagh
RealName(TM)

Posts: 2,715
Registered: 5/25/06
Re: Java Library for Amazon SQS
Posted: Jun 11, 2008 6:31 PM PDT   in response to: Mark Rebuck
 
  Click to reply to this thread Reply

I think the AWS client code requires you to grab the dependencies yourself (as do a lot of them out there). I'll shamelessly plug my own SQS client, which turns out to handle quite a bit of the overall SQS traffic! http://code.google.com/p/typica/
There are just 4 dependencies, less if you use Java 6 (which has JAXB built in).

David


Elena@AWS
Posts: 155
Registered: 2/9/06
Re: Java Library for Amazon SQS
Posted: Jul 28, 2008 9:59 PM PDT   in response to: pelagopaul
 
  Click to reply to this thread Reply

Hi pelagopaul,

I've responded here:

http://developer.amazonwebservices.com/connect/thread.jspa?threadID=23467

-elena


pelagopaul
Posts: 2
Registered: 7/28/08
Re: Java Library for Amazon SQS
Posted: Jul 28, 2008 11:22 AM PDT   in response to: Mark Rebuck
 
  Click to reply to this thread Reply

I have not yet created a queue. When I run a ListQueues request, I get back what appears to be well-formed XML with an empty <ListQueuesResult>. This looks right. However, the unmarshal call throws an exception:

javax.xml.bind.UnmarshalException: unexpected element (uri:" http://queue.amazonaws.com/doc/2008-01-01/", local:"ListQueuesResponse"). Expected elements are <{}Attribute>,<{}CreateQueue>,<{}CreateQueueResponse>,<{}CreateQueueResult>,
<{}DeleteMessage>,<{}DeleteMessageResponse>,<{}DeleteQueue>,
<{}DeleteQueueResponse>,<{}Error>,<{}ErrorResponse>,<{}GetQueueAttributes>,
<{}GetQueueAttributesResponse>,<{}GetQueueAttributesResult>,<{}ListQueues>,
<{}ListQueuesResponse>,<{}ListQueuesResult>,<{}Message>,
<{}ReceiveMessage>,<{}ReceiveMessageResponse>,
<{}ReceiveMessageResult>,<{}ResponseMetadata>,<{}SendMessage>,
<{}SendMessageResponse>,<{}SendMessageResult>,
<{}SetQueueAttributes>,<{}SetQueueAttributesResponse>

Thoughts?




Reviews
Create Review Write a Review

jar, Aug 8, 2008 9:25 AM
Reviewer: zernoveanu
It would be nice to have an easy way to download the amazon-queue-2008-01-01-java-library.zip file

Solve my problem that i had with typica, Feb 5, 2010 7:03 AM
Reviewer: ys276
Got problem with messages from php to java with typica. It works fine with this lib.
Welcome, Guest Help
Login Login