Configuring the System to use Simple Queue Service
In this lab, we are creating a queue for the orders to control the traffic of orders. The orders will first move to the queue then it will be processed to the database.
Amazon Simple Queue Service (SQS)
SQS is a fast, reliable, salable, fully managed message queuing service provided by AWS. SQS can manage to transmit any amount of data without data loss. We are using SQS to queue the orders in DinoStroe project.
I have created a new queue in the SQS console and named it as dinoorders.
.
I have created a new queue in the SQS console and named it as dinoorders.
.
Then I have tested the queue by sending a message in ‘Queue Actions’
It has successfully come to the queue.
I started polling and I could see my message. Now I have confirmed that my SQS is properly working, then I have deleted the test message.
Now I have to configure the Visual Studio program to move the orders to the queue. I have placed some coding in Checkout.aspx.cs to point it to the queue.
Then right click on the DinoStore – References object, and Manage NuGet Packages. Search for and install the Json.NET package. This allows the shopping cart to be serialised as a JSON object and added to the queue.
Next, I had to add credentials and location of the SQS in web config file. I have added following comments with the region, access key, and secret key.
<add key="AWSRegion" value="YOUR REGION HERE"/>
<add key="AWSAccessKey" value="YOUR ACCESS KEY HERE"/>
<add key="AWSSecretKey" value="YOUR SECRET KEY HERE"/>
Now the time to check the order queue, I have built the project and logged in to the DinoStore with the user and made a purchase.
Then I have checked the SQS queue and found the purchase in the queue.
In the next step, we need to pull the order from SQS to RDS.We now need to add a new application to the project that can pull the orders from the queue. I have already prepared the application called 'NET702.DinoStore.OrderProcessor'. I have added the order processor by right-clicking on the Solution Dinostore\Add\Add Existing project. Then inserted the dinoorders queue URL into the NET702.DinoStore.OrderProcessor ‘Program.cs’ code.
Then edited the app.config file by giving the access keys and region details. Changed the StoreSqlDb server connection string to the dinostoreinstance URL, and add DB username and password to this line.
Then rRight click on NET702.DinoStore.OrderProcessor project and select ‘Set as Startup Project’ this will make the program to run from this application.
Right click the new project, choose Properties-Signing and untick the ‘Sign the ClickOnce manifests’
Then I built the project to fetch the order from the queue but I received several errors. Then I have updated NuGets in the order processor references.As well as, I have fixed some errors in the coding and then it was successfully built.
Now it has received and deleted a message from the queue and it started polling the queue.
To verify, I have checked the SQS and found the queue has been cleared.
Then I have checked the database and found the order has been created in the orders table.
No comments:
Post a Comment