Lab 4. Configuring the System to use Simple Queue Service


In this lab you will create Simple Queue Service to manage the orders that is done through the dinostore webstore.

Simple Queue Service

Amazon Simple Queue Service (SQS) is a fully-managed message queuing service for reliably communicating among distributed software components and microservices – at any scale. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be always available. SQS standard queues offer maximum throughput, best-effort ordering, and at-least-once delivery.

By doing this lab you will learn:

  • How to create SQS
  • How to configure it & Compile the codes in Visual studio which is  related to SQS
  • How to place an Order

The image shown below is the architecture for this lab.


To create a SQS click on services and select Simple Queue Service and click on Get Started Now. Click ‘Create a New Queue

Screenshot (13)

In Create New Queue window give the following details.
Queue name=‘dinoorders’
Choose the right region.
Select ‘Standard Queue’

Screenshot (14)

Keep the rest default values and click on Create.

Screenshot (15)

To test the queue click on the queue you created.

Screenshot (16)

Click on Actions and select send a Message.

Screenshot (17)

In the message body type a message and click on send message.

Screenshot (18)

when you have clicked on send message, You will get an Notification if the message is sent.

Screenshot (19)

To view the message click on the Queue you created, click on Actions and select View/Delete Messages.

Screenshot (20)

Click on Start polling messages to read the messages.

Screenshot (21)

Tick on the box which is at the left of the message and click on Delete Messages.

Screenshot (22)Screenshot (23)

Click on yes delete checked messages.

Screenshot (24)

Now go to your visual studio and click on your project, from the solution explorer click on secure > expand it and select Checkout.aspx.cs. you need to Remove the code from ‘protected void btnPurchase_Click(object sender, EventArgs e)’ down to and including ‘Response.Redirect(“PaymentConfirmation.aspx”);’. (line 66 to 126 inclusive). This code inserts order information directly into the database, and hence doesn’t scale well.

Add the following new ‘using’ statements under the existing set:

using Amazon SQS;
using Amazon.SQS.Model;
using Newtonsoft_json;

Screenshot (25)

Replace the code with the following code:

protected void btnPurchase_Click(object sender, EventArgs e)
//get shopping cart
ShoppingCart cart = Session.Contents[“cart”] as ShoppingCart;
//get user id
MembershipUser user = Membership.GetUser();
string userId = user.ProviderUserKey.ToString();
//add payment info
cart.CcType = ddlCcType.SelectedItem.Text;
cart.CcNumber = txtCcNumber.Text;
cart.CcExpiration = txtExpire.Text;
//create message for queue
using (AmazonSQSClient client = new AmazonSQSClient())
var jsoncart = Newtonsoft.Json.JsonConvert.SerializeObject(cart);
SendMessageRequest request = new SendMessageRequest();
request.QueueUrl = “”;
request.MessageBody = jsoncart;
SendMessageResponse response = client.SendMessage(request);
//clear out cart
Session[“cart”] = cart;
//send user to confirmation page

Screenshot (26)

Make sure that you install Jason.NET.web package. To install this package click on > project > Manage NuGet packages and search for Json.NET.web and install it.

Screenshot (28)

Now go to your web.config file and add the credentials to do this you have to find the code after ‘ValidationSettings:UnobtrusiveValidationMode’ and insert these codes.

<add key=”AWSRegion” value=”YOUR REGION HERE”/>
<add key=”AWSAccessKey” value=”YOUR ACCESS KEY HERE”/>
<add key=”AWSSecretKey” value=”YOUR SECRET KEY HERE”/>

Note: Provide the security details that you obtain when you create a Security key.

Screenshot (29)

To test your system open it in browser.

Screenshot (30)

Log in with the credentials.

Screenshot (31)

Provide fake fake cc details and click on buy now.

Screenshot (32)

when you have done it successfully you will get a message as shown below, If not you should refer to your codes again.

Screenshot (33)

Go to your cloud system and you will able to see the order message in your sqs.

Screenshot (34)

Go to visual studio again and click on the solution explorer to add an existing project. To add an existing project right click on solution explorer and select the project from your local computer and select ‘NET702.DinoStore.OrderProcessor‘ click on open.

Expand the project and click on ‘program.cs’ and insert your queue URL to the following code lines

Screenshot (35)

After the changes are done in ‘program.cs’, Select App.config file and insert the follwing information

Insert your AWSRegion at the ‘add key’point.
Insert your access keys at the ‘add key’ points.

As for me i have inserted these information which is shown below:

Change your StoreSqlDb server connection string to your dinostoreinstance URL, and add your DB user name and password to this line.

Screenshot (36)

Right click on NET702.DinoStore.OrderProcessor project and select ‘Set as Startup Project’

Screenshot (38)

Right click the new project, choose Properties-Signing and untick the ‘Sign the ClickOnce manifests’

Screenshot (39)Screenshot (40)

Run the NET702.DinoStore.OrderProcessor application. This will pull the order message from the queue, add it to the database, and delete the message. This app will sit and poll the message queue until X is pressed.

Screenshot (41)Screenshot (42)Screenshot (43)

As you can see when you have executed now you can’t see any messages in your sqs.

Screenshot (44)

To check again whether its working or not log in to the site with your credentials and make an order. and go to visual studio and run the program again and check if the message is deleted.

Screenshot (45)Screenshot (46)Screenshot (47)

After all these steps you have completed the lab successfully.

Errors and Its Solutions


For the error message “ReceiveMessageRequest” does not not exists go yo your programs.cs get the line number from your error list and add an ‘s’ and add a ‘s’ to Attribute as well.


By the end of this lab you have learned:

  • How to create SQS
  • How to configure it & Compile the codes in Visual studio which is  related to SQS
  • How to place an Order

Budget Plan

You have to pay for what you use. there won’t be any minimum fee. You can get started for free and all the customers can make 1 million Amazon SQS requests for free each month. In this lab i’m using standard queue, If you exceed the free tier limits you will have to pay $0.40 ($0.00000040 per request) and $0.090 up to 10TB(Data Transfer).


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 )

Google+ photo

You are commenting using your Google+ 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