Lab 4: Configuring the system to use Simple Queue Service

In SQS service, a new Queue can be created. The queue name is to be called ‘dinoorders’.
001 Create SQS

After sending a message through ‘Queue Actions’, the queue screen can be refreshed to check whether there are messages are available.
002 Send Message

The message can be viewed by right-clicking on the queue and selecting the view/delete message in the pop-up tab.

The messages can then start polling. Once the message has finished polling, the message can be deleted and polling stopped.
003 Polling Messages



In Visual Studio, in the Net702.DinoStore Checkout.aspx.cs, adjustments to the code need to be made:
Firstly, the lines of code from line 66 to 126 (inclusive) needs to be deleted. The lab script explains that this “code inserts order information directly into the database, and hence doesn’t scale well.”
Secondly, the deleted code needs to be replaced with the following code:
000a Code exceprt 1000b Code excerpt 2
The lab script states that “this code inserts the order information into the queue so the system can handle bursts.”
005 Update VS Checkout_aspx_cs

To ensure that the solution handles the aspx.cs file code properly, the following ‘using’ statements are added to the current set;

using Amazon.SQS;
using Amazon.SQS.Model;
using NewtonSoft.Json;

Still in Visual Studio, under Tools->NuGet Package Manager->Package Manager Console, the Json.Net package needs to be installed. This package “allows the shopping cart to be serialized as a JSON object and added to the queue.” As stated in the lab script.
008 Json_Net package

In the Visual Studio Net702.DinoStore web.config file, AWS account credentials  are added below the line of code: ‘ValidationSettings:UnobtrusiveValidationMode’

<add key=”AWS Region” value=”Your Region Here”/>
<add key=”AWSAccessKey” value=”Your Access Key Here”/>
<add key=”AWSSecretKey” value=”Your Secret Key Here”/>

The updated system can be checked by building and browsing the project and creating an order. The Amazon queue service should have received a message in response to the order creation.

This slideshow requires JavaScript.

The next step is to add an application that is able to pull orders from the queue. This application is a file that needs to be added to the the Visual Studio DinoStore project. The lab script describes the order processor application as “console project code [that] polls the message queue for up to ten messages at once, and de-serializes  the JSON object back into a shopping cart objects, deletes the processed messages, and adds the orders to the MySQL cloud database.”

In my case I added the OrderProcessor file to the Visual Studio code, by right clicking on Solution ‘Net702.DinoStore’ under the Solution Explorer window, and clicking Add->Existing Project, then browsing for the OrderProcessor Visual C# project file.

Within the OrderProcessor project in Visual Studio, in the program.cs file, the SQS URL is added into two places; in place of request.QueueURL, and batchRequest.QueueURL.
000d VS Request000c VS DeleteRequest

In the App.config file, the code is adjusted by adding the AWSRegion and access keys at the add key point, and the StoreSqlDB server connection string is changed to the dinostoreinstance URL with the username and password added to the line.
Inked023 Key Snap

Once the code is adjusted, the project is ‘Set as Startup Project’ by right-clicking on the ‘Net702.DinoStore.OrderProcesor’ file under Solution Explorer. The file then is right-clicked again to access the Properties. In the Properties tab, Signing, the ‘Sign the ClickOnce manifests’ needs to be un-ticked.
013 Unticking the ClickOnce manifests

Before running the OrderProcessor application, the MySQL AWS DinoStore order table will have nothing in it.
014 Dinostore Orders Table Empty

By running the application, the order message is pulled from the queue, added to the database, and then deleted. The app doesn’t recognize whether there are available messages or not, so it runs until the program is exited.
019 OP Pop up for Polling

Now in the MySQL AWS DinoStore order table, the order message data should be displayed.
021 MySQL w Order Table Full


My first challenge that I faced was adding the OrderProcessor file to the Visual Studio code as I am not familiar with Visual Studio. My first attempts were to use the Project tab and ‘add existing item’. This wasn’t successful as the item imported into the code would only be part of the file, and I needed all of file to be contained in the code. My resulting method came from realizing that the Solution explorer appeared to contain multiple projects under the same solution. I determined that I needed to get my OrderProcessor project into this DinoStore solution, so I right-clicked on ‘Solution ‘Net702 DinoStore’ (2 projects) and tried the option of ‘add->existing project’, which was successful.

The second challenge that I encountered was running the OrderProcessor application. The build would continually fail with various code-based error reports that I attempted to fix.
016 2 Errors and 1 Warning in VS
Through attempting to fix the code errors, I was able to reduce the error number from 19 errors to 2 errors. However these two remaining errors involved a variable called ‘ReceiveMessageResult’ that Visual Studio could not determine. I attempted to solve it by trying the variable of ‘ReceiveMessageResponse’, but it also did not work.
By right-clicking on the variable and clicking on to ‘Go To Definition’ option, I was able to see its inception, and the requirements needed to cause it to run.
017 ReceiveMessageResponse Definition
ReceiveMessageResponse is an AWS based variable, but wasn’t able to transfer into the Program.cs file where the other variable was being used.

I was aware that this particular lab had caused some troubles for my classmates, so I messaged them to ask for assistance on how they had managed to solve this problem. Their response surprised me as it had not been in my considerations; the way to solve this issue was not a matter of correcting a mistaken variable, but on having the correct packages for the OrderProcessor project. Where I had been thinking that every problem was purely an issue with the code, I had forgotten to consider that the imported project wouldn’t automatically contain the correct NuGet packages.
022 Packages_Config for Challenges Section
By downloading and installing the correct versions and types of NuGet packages for the OrderProcessor project, the ReceiveMessageResponse variable was able to be recognized, and the build to succeed.


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 )

Google+ photo

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

Connecting to %s