December 2, 2020
Understanding Simple Queue Service Usage through CFML- 1
Comments
(0)
December 2, 2020
Understanding Simple Queue Service Usage through CFML- 1
Newbie 10 posts
Followers: 0 people
(0)

Hi CFNext users, 

I will be covering AWS SQS integration with ColdFusion. This post mostly revolves around below items:

  1.  AWS SQS usecase
  2.  Setting AWS credentials
  3.   Create Queue
  4.   Setting Queue Attributes
  5.   Send, Receive and Delete messages
  6.   Purge and Delete Queue.

Prerequisite: CFNext, AWS account with an access key ID and a secret access key.

SQS described as per Amazon AWS:

“Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware and empowers developers to focus on differentiating work. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.”

Let’s quickly go through the some of real time usecases of SQS:

  1. Photo Album: Let’s say you have a service where people upload photos from their mobile devices. Once the photos are uploaded , then your service needs to do a bunch of processing of the photos, e.g. scaling them to different sizes, applying different filters, extracting metadata, etc. One way to accomplish this would be to post a message to an SQS queue (or perhaps multiple messages to multiple queues, depending on how you architect it). The message describe work that needs to be performed on the newly uploaded image file. Once the message has been written to SQS, your application can return a success to the user because you know that you have the image file and you have scheduled the processing. In the background, you can have servers reading messages from SQS and performing the work specified in the messages. SQS guarantees that a message will be delivered eventually so you can be confident that the work will eventually get done.
  2. Auction website: Let’s go through another example using auction website name as XYZ. Essentially, the website will track user bids by storing them in a FIFO (first in, first out) queue, breaking ties by awarding the bidder who submitted the bid first. Amazon SQS is also able to flexibly, reliably handle a number of challenges and added complexity for this platform, such as increased messages and additional processing time.

Get Started

1.  AWS Credentials:

You can go to URL and see how to get Access Key Id and Security Access Key. 

https://aws.amazon.com/blogs/security/how-to-find-update-access-keys-password-mfa-aws-management-console/ 

We will specify AWS credentials and configuration in struct and use it throughout the examples:

 awsCred  = {
                "credentialAlias" : "TestCloud",
                "vendorName" : "AWS",
                "region" : "us-east-1",
                "secretAccessKey" : "<AWS Secret>",
                "accessKeyId" : "<AWS Key>"
            }            
 awsConf  = {
                "serviceName" : "SQS"
            }
sqs=cloudService(awsCred, awsConf);

We can also set the aws credentials through admin api and admin ui.    

2.  Create a Queue:

The first in Amazon SQS is to create queue.

With Amazon SQS, messages can be processed in two ways:

  •  Standard queues: This is the default type, which supports at-least-once message delivery. Your app should be able to handle messages arriving more than once and out of order. 
  •  FIFO queues: FIFO (first-in-first-out) model is used to process messages only once and in a strict order. 

The following example will create a new queue named StandardQueue:

stdQueue = sqs.createQueue("StandardQueue");

3.  Set Queue Attributes:

Below is list of queue attributes can set as per your requirement:

  1. Default Visibility Timeout
  2. Message Retention Period
  3. Maximum Message Size
  4. Delivery Delay
  5. Receive Message Wait Time
  6. Content-Based Deduplication
setQueueAttributesMetadata = {
        "attributes"={  
                      "VisibilityTimeout"="10",
                      "MessageRetentionPeriod"="100",
                      "MaximumMessageSize"="1024",
                      "DelaySeconds"="10",
                      "ReceiveMessageWaitTimeSeconds"="20"                
                 }
           };
sqs.setAttributes(setQueueAttributesMetadata);

Note : I will be sharing another post to explain about other AWS SQS functionality.

I will be happy if you come with few queries, question or any thoughts on AWS SQS.

0 Comments
Add Comment