Software Development

Java – Using Amazon Simple Queue Service (AWS SQS)

This post shows how to use Amazon Simple Queue Service (SQS) in Java with Eclipse using the AWS Toolkit Plugin for the IDE. It also shows how to create queues and send and receive messages from them.

Java, Amazon Simple Queue Service, And Other Requirements

We used the following items for this post.

  • An AWS Account
  • Fast Internet Connection
  • Eclipse Mars.2 Release (4.5.2)
  • The AWS Toolkit Plugin for Eclipse
  • Java 8 – JDK
  • AWS SDK for Java
    • Version: 1.11.205

Step 1 – Create A Queue In Amazon Simple Queue Service

Before we create a queue in Amazon Simple Queue Service (SQS), we need an AWS account. Then, proceed with the queue creation either using the AWS Management Console, Eclipse (using the AWS Toolkit Plugin), or via Java codes.

To create via the AWS Management Console, sign in to the AWS account and proceed to the Simple Queue Service (SQS). Then, click the Get Started Now button.

Alternatively, we can create a queue in Amazon Simple Queue Service (SQS) in Eclipse for Java using the AWS Toolkit Plugin. However, the plugin may require providing a credential to an AWS account.

Then, proceed to the AWS Explorer tab, choose Amazon SQS, and click the Create New Queue option.

On the other hand, we create a queue in the Amazon Simple Queue Service using Java codes. Consider the following sample codes. However, this assumes we are using a dependency on the AWS SDK for Java.

Step 2 – Create an AWS Project

Next, we create an AWS project in Eclipse.

Then, choose AWS Java Project and click Next.

Then, provide the Project name, Group ID, and Artifact ID. Optionally, we can ignore the checkboxes in the AWS SDK for Java Samples. Finally, click Finish.

Wait until the creation process completes.

Step 3 – Create simple Java Codes

Next, we craft some Java codes to work with the Amazon Simple Queue Service. Consider the following codes that send messages to a queue.

We get the following output on the IDE console when we run the codes.

Java Amazon Simple Queue Service

Then, we can check if the Amazon Simple Queue Service received our message.

Java Amazon Simple Queue Service

 

Java Amazon Simple Queue Service

Java Codes to read Messages from a Queue

The following are simple Java codes that retrieve the messages from our SQQ queue in the cloud.

This outputs:

Java Amazon Simple Queue Service

Our queue will be empty.

Download the codes

For more information, please download the Java codes that send a message to Amazon Simple Queue Service on GitHub. Also, check out the following links for additional references.

  1. AWS SDK for Java
  2. Working with Amazon SQS Message Queues

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like