In this tutorial, you will learn how to set up asynchronous messaging with Amazon Simple Queue Service (Amazon SQS). Amazon SQS is the AWS service that allows application components to communicate in the cloud. You will use the Amazon SQS console to create and configure a message queue, send a message, receive and delete that message, and then delete the queue.

The AWS services you use in this tutorial are within the AWS Free Tier.

Using messaging on AWS requires an account

Create a Free Account

AWS Free Tier includes 1,000,000 requests of Amazon Simple Queue Service.

View AWS Free Tier Details »

 


a. When you click here, the AWS Management Console will open in a new browser window, so you can keep this step-by-step guide open.  When the screen loads, enter your user name and password to get started. Then type queue in the search bar and select Simple Queue Service to open the console.

tmt_send-receive-async-messages_1a

(click to zoom)

tmt_send-receive-async-messages_1a

b.  If the SQS console landing page appears, as shown on by the screenshot, click Get Started Now. If you don't see this page, skip to the next step.

tmt_send-receive-async-messages_1b

(click to zoom)

tmt_send-receive-async-messages_1b

In this step, you will create and configure an Amazon SQS queue. A queue is a reliable, highly-scalable buffer that stores messages as they travel between distributed applications or microservices. Queues help to decouple applications, connect microservices, batch tasks, or store notifications.

Our use case for this tutorial will simulate the storage of incoming orders from an e-commerce application.


a. First, we will create a simple queue that stores orders that are placed on the store. Enter Orders in the Queue Name field.  

tmt_send-receive-async-messages_2a

(click to zoom)

tmt_send-receive-async-messages_2a

b. For this tutorial, we do not require strict ordering, so we won’t make any changes to the queue type. Leave Standard Queue selected.  

tmt_send-receive-async-messages_2b

(click to zoom)

tmt_send-receive-async-messages_2b

c. You can configure your queue to modify settings such as retention period, maximum message size and delivery delays. For this tutorial, we will keep the default parameters. Choose Quick-Create Queue.

tmt_send-receive-async-messages_2c

(click to zoom)

tmt_send-receive-async-messages_2c

d. Your new queue is created and selected in the queue list.

tmt_send-receive-async-messages_2d

(click to zoom)

tmt_send-receive-async-messages_2d

Once you have created your queue, it is ready to receive messages from the online store that capture the details of each new order.


a.  Your queue is already selected in the list. From Queue Actions, select Send a Message. The Send a Message to Orders dialog box is displayed.

tmt_send-receive-async-messages_3a

(click to zoom)

tmt_send-receive-async-messages_3a

b. The Send a Message to Orders dialog box is displayed. On the Message Body tab, enter the following text to represent a sample order:

1 x Widget @ $29.99 USD
2 x Widget Cables @ $4.99

tmt_send-receive-async-messages_3b

(click to zoom)

tmt_send-receive-async-messages_3b

c. Select the Message Attributes tab to add some optional metadata about this message for easy processing. Let’s add an order type to the order. Enter Order-Type in the Name field, String in the Type field, and Online in the Value field. Click Add Attribute.

tmt_send-receive-async-messages_3c

(click to zoom)

tmt_send-receive-async-messages_3c

d. To send the message immediately, click Send Message. Confirmation that your message was sent is displayed in the Send a Message to Orders dialog box. Click Close.

tmt_send-receive-async-messages_3d

(click to zoom)

tmt_send-receive-async-messages_3d

After you send a message to a queue, another application can consume it from the queue and do something with it. In this example, you will simply retrieve the message to view the order, and then delete it.


a. Ensure that your Orders queue is selected in the queue list. Next, from Queue Actions, select View/Delete Messages.

tmt_send-receive-async-messages_4a

(click to zoom)

tmt_send-receive-async-messages_4a

b. The View/Delete Messages in Orders dialog box is displayed. When you request a message from a queue, you don't specify request a specific message. Instead, you specify the maximum number of messages (up to 10) that you want to retrieve.

Click Start Polling for messages to retrieve messages from the queue.  

tmt_send-receive-async-messages_4b

(click to zoom)

tmt_send-receive-async-messages_4b

c. Once a consumer has received and processed a message, it can be deleted from the queue. Select the message that you want to delete and then choose Delete 1 Message.

tmt_send-receive-async-messages_4c

(click to zoom)

tmt_send-receive-async-messages_4c

d. The Delete Messages dialog box is displayed. Check the box next to the message and click Yes, Delete Checked Messages. The selected message is deleted. Choose Close.

tmt_send-receive-async-messages_4d

(click to zoom)

tmt_send-receive-async-messages_4d

When you no longer need to use an Amazon SQS queue, we recommend that you delete the queue as a best practice.


a. In the queue list, select the Orders queue. Then, from Queue Actions, select Delete Queue.

tmt_send-receive-async-messages_5a

(click to zoom)

tmt_send-receive-async-messages_5a

b. The Delete Queues dialog box is displayed. You can still delete your queue, even though you still have messages in it. Choose Yes, Delete Queue. The queue is deleted.

tmt_send-receive-async-messages_5b

(click to zoom)

tmt_send-receive-async-messages_5b

You have created your first Amazon Simple Queue Service (Amazon SQS) message queue, sent messages to your queue, retrieved and deleted messages, and then deleted the queue. You are now ready to use Amazon SQS queues to store and move data between distributed application components and microservices.

Now that you have learned how to use Amazon Simple Queue Service to send and receive messages, pick one of the following options to further hone your messaging skills.

Learn more

Get an overview of the capabilities, components, and use cases for message queues on Amazon Web Services (AWS). Visit the Amazon SQS webpage »

Dive deeper

Explore the different types of queues, main features and architecture of Amazon Simple Queue Service. Read the documentation »

See it in action

Hear how customers like Capital One use Amazon SQS and Amazon SNS to decouple and scale applications. Watch the webinar »

Yes
No