Now that we have the code in place to make the web service request and process the response, we can compile (if necessary) and run the example application. There are two command-line sample applications that Amazon provides for the Simple Queue Service. The first sample application (Enqueue) creates a queue with the specified name (if one does not exist already) and then sends (enqueues) a message containing the message text specified into the queue. The second sample application (Dequeue) finds a queue with the given name (if one exists), and it attempts to read a message from the queue. The files necessary to run the sample applications are either included with the sample code or generated when the project is compiled. The following table lists the sample application files.
| Language | Example File |
|---|---|
| Java | Enqueue.java and Dequeue.java |
| C# | Enqueue.exe and Dequeue.exe |
| Perl | sqs-enqueue-sample.pl and sqs-dequeue-sample.pl |
Compile the example by entering the following command:
javac -classpath < your classpath here > *.java
Run the example to create a queue and send a message by entering the following command:
java -classpath < your classpath here > EnqueueSample -q "queue name" -m "message string"
Run the example to retrieve a message and then delete it by entering the following command:
java -classpath < your classpath here > DequeueSample -q "queue name"
Please ignore the following warnings from Axis, if you see them while running Enqueue and Dequeue samples:
Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
WARN JavaUtils: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Build the sample solution by pressing F6 (Build Solution).
Two executable files are created, Enqueue.exe and Dequeue.exe. Both have an associated wse3policyCache.config that needs to be in the same directory as the executable when the application is run. This .config file references the certificate used to authenticate the request. After the solution is built, copy the .exe and associated .config file to the same location and run the .exe.
To create a queue and send a message to it, type the following command at the command line:
Enqueue "queue name" "message body"
To retrieve a message and then remove it from the queue, type the following command at the command line:
Dequeue "queue name"
The sample application sqs-enqueue-sample.pl takes the following arguments: queue name, message string, "REST" or "Query" (optional - defaults to Query). Run the example to create a queue and send a message by entering the following command:
perl sqs-enqueue-sample.pl "SomeQueueName" "SomeMessage"
The second sample application sqs-dequeue-sample.pl takes the following arguments: queue name and "REST" or "Query" (optional - defaults to Query). To run the sample, type the following command at the command line:
perl sqs-dequeue-sample.pl "SomeQueueName" "Query"