Setting up Amazon Simple Queue Service

Amazon Web Services

                                        In this article, we will see how to setup the Amazon Simple Queue Service through AWS console and how to consume the messages using AWS SDK. To setup Amazon SQS, follow the below steps.

Step 1: From the AWS console, select the “SQS”.

AWS Simple Queue Service

Step 2: Click on “Create New Queue” and provide the queue name.

AWS Simple Queue Service

Step 3: Click on the “Queue Actions” to send the message to the queue.

AWS Simple Queue Service

Step 4: Collect the “Queue URL” from the AWS Console.

AWS Simple Queue Service

Step 5: We will write a simple consumer application using AWS JAVA SDK.

import java.util.List;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;

public class AWSSQSSampleConsumer {

public static void main(String[] args) throws Exception {

AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider("<Provide Credentials file path here>", "sample").getCredentials();
} catch (Exception e) {
throw new AmazonClientException("Cannot load the credentials from the credential profiles file. ", e);

AmazonSQS sqs = new AmazonSQSClient(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);

System.out.println("Getting Started with Amazon SQS");

try {
String myQueueUrl = "<Provide the Queue URL here>";

// Receive messages
System.out.println("Receiving messages from MyQueue.\n");
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
for (Message message : messages) {
System.out.println(" Message");
System.out.println(" MessageId: " + message.getMessageId());
System.out.println(" Body: " + message.getBody());

// Delete a message
System.out.println("Deleting a message.\n");
String messageRecieptHandle = messages.get(0).getReceiptHandle();
sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle));

      } catch (AmazonServiceException ase) {
    } catch (AmazonClientException ace) {

Ride on Cloud Computing !!! and Happy Queuing !!!



Siva Janapati is an Architect with experience in building Cloud Native Microservices architectures, Reactive Systems, Large scale distributed systems, and Serverless Systems. Siva has hands-on in architecture, design, and implementation of scalable systems using Cloud, Java, Go lang, Apache Kafka, Apache Solr, Spring, Spring Boot, Lightbend reactive tech stack, APIGEE edge & on-premise and other open-source, proprietary technologies. Expertise working with and building RESTful, GraphQL APIs. He has successfully delivered multiple applications in retail, telco, and financial services domains. He manages the GitHub( where he put the source code of his work related to his blog posts.

Tagged with: , ,
Posted in Cloud Computing
One comment on “Setting up Amazon Simple Queue Service
  1. bhaskar says:

    Good and useful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Java Code Geeks
Java Code Geeks
%d bloggers like this: