[object Object]

Amazon SQS

The Amazon Simple Queue Service (SQS) is a fast, reliable, scalable, fully managed message queuing service.
Amazon SQS makes it simple and cost-effective to decouple the components of a cloud application.
You can use Amazon SQS to transmit any volume of data, at any level of throughput, without losing messages or requiring other services to be always available.

Cloud CMS Application Server

The Cloud CMS Application Server is a middle-tier cluster that sits between your mobile/web application and the
Cloud CMS API. It provides a wide range of request-time services for your front-end application for fast
performance, object caching and more.

It features integration with Amazon SQS as a means of listening to events that occur within the Cloud CMS API.
When content is created, updated or deleted within the Cloud API, notifications are received and placed onto
an Amazon SQS Queue.

The Cloud CMS Application Server cluster hears these messages and responds by invalidating cache and doing the
necessary bookkeeping to keep the middle-tier consistent with changes from your editorial team.

Configuration

Cloud CMS provides an application server built on top of Node.js that provides a number of very compelling
features for web sites and mobile applications. Among it's many features is an Amazon SQS integration that allows for
it to listen to notification events as they are published by the Cloud CMS API.

Amazon SQS is not the same thing as Amazon SNS. SQS is Amazon's Simple Queue Service. It's a different service
that you hook up as a subscriber to your Amazon SNS Topic. When notification events are sent from Cloud CMS to the
Amazon SNS topic, those events are handled by looking for subscribers.

By default, there are no subscribers which means that those events effectively don't do anything. However, you can hook
up subscribers for different behaviors - such as firing off to HTTP listeners, triggering push notifications, sending
emails and handing events to an Amazon SQS queue.

It is this latter case that we're most interested in since queues provide a way for clustered application server
instances to "hear" things that happened recently and catch up by invalidating cache as they come online and seek
to become useful.

If you're using or extending the Cloud CMS application server, you may wish to incorporate the following:

Create an Amazon SQS Queue

Within your Amazon account, go into SQS and create a new Queue. Be sure to jot down the queue url as this will
be important later. It will look something like this:

https://sqs.us-east-1.amazonaws.com/123456789012/my-message-queue

Also take note of the '''region''' that you created the queue in. It might look like this:

us-east-1

Use these settings for the queue:

Default Visibility Timeout		0 seconds
Message Retention Period		4 hours
Maximum Message Size			256 KB
Delivery Delay					0 seconds
Receive Message Wait Time		0 seconds

Use Redrive Policy				false (unchecked)

More detail on creating queues is provided here: AWS Queue Creation

Connect your Queue to your SNS Topic

Go back into Amazon SNS and find your topic. Add a subscriber. The subscriber should be your Amazon SQS queue!
That's really all there is to it. Messages sent to your SNS topic will now be forwarded on to your queue.

Set up an IAM User

As with SNS notifications, you will want to have an IAM User set up that your Node.js code can use to retrieve
messages. You can either use the same user information from the SNS setup or you can create a new user. Whatever you
do, be sure that the user has full or sufficient authorities against SQS or the SQS queue. Jot down the user's
'''accessKey''' and '''secretKey'''.

Configure your Node.js application

Your local Node.js application which "requires" and initializes the Cloud CMS Server must be configured to listen
for notification events off of the Amazon SQS queue.

Add the following object to the configuration section when starting the server.
Replace the property values with those from previous configuration steps in this section:

"notifications": {
    "enabled": true,
    "type": "sqs",
    "configuration": {
        "queueUrl": "<queue url>",
        "accessKey": "<accessKey>",
        "secretKey": "<secretKey>",
        "region": "<region>"
    }
}

And then restart your Node app. When your Node app comes online, you should see a message indicating that the connection
to SQS was established and is good to go.

For more information on SQS within Cloud CMS, see the Application Server documentation.