This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Using Simple Queue Service

Using Simple Queue Service

Eucalyptus Simple Queue Service (SQS) is a message queuing service that enables you to decouple your services and distributed systems.

SQS reduces the overhead of managing and operating message oriented middleware and facilitates robust cloud architectures when used with other services such as Auto Scaling.

1 - Simple Queue Service Concepts

This section describes the important concepts for the Simple Queue Service (SQS)

Queues and Queue URLs

A queue is a named destination for messages in an account. A queue has a URL that uniquely identifies it on the cloud.

Delivery and Visiblity

When a message is delivered to a client it is hidden from other clients for a period to prevent duplicate handling. If the message is not handled by the first client it will later become visible for handling by other clients.

Dead-letter Queues

A dead-letter queue can be used for undeliverable messages. Using a dead-letter queue allows for handling of messages that would otherwise not be processed.

Delay Queue

A delay queue allows messages to be available from a queue after a delay period rather than as soon as messages are sent to the queue.

Polling Style

Short or long polling can be used when receiving messages. For short polling there is an immediate response whether a message is available or not. For long polling a delay of up to 20 seconds is used and the response will occur when a message is available or when the given timeout is reached even if there is no message.

2 - Simple Queue Service Overview

Using the AWS CLI

The AWS CLI can be used to access the Simple Queue Service (SQS). Use of the Eucalyptus AWS CLI plug-in is assumed in these examples.

To list queues:

# aws sqs list-queues
QUEUEURLS	http://sqs.mycloud.example.com:8773/000575948401/queue1
QUEUEURLS	http://sqs.mycloud.example.com:8773/000575948401/sqs-1-DeadLetterQueue-N7AHZIWZEW3H5

Send a message:

# aws sqs send-message --queue-url http://sqs.mycloud.example.com:8773/000575948401/queue1 --message-body "TEST MESSAGE"
d41d8cd98f00b204e9800998ecf8427e	2b3ce69548da118bf617bfdd33a06108	daedefab-669b-47a4-a801-8b84e747c11c

Receive a messge:

# aws sqs receive-message --queue-url http://sqs.mycloud.example.com:8773/000575948401/queue1
MESSAGES	TEST MESSAGE	2b3ce69548da118bf617bfdd33a06108	d41d8cd98f00b204e9800998ecf8427e	9cc9bc8c-c201-4a27-9f7f-94924a79968a	000575948401:queue1:9cc9bc8c-c201-4a27-9f7f-94924a79968a:3

Using CloudFormation

A CloudFormation template can be used to manage SQS resources. The following template is an example showing the:

  • AWS::SQS::Queue
  • AWS::SQS::QueuePolicy

CloudFormation resources:

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  SQS queue and queue policy template
    
Resources:

  Queue:
    Type: AWS::SQS::Queue
    Properties:
      RedrivePolicy:
        deadLetterTargetArn: !GetAtt 'DeadLetterQueue.Arn'
        maxReceiveCount: 5
      DelaySeconds: '10'
      MaximumMessageSize: '65536'
      MessageRetentionPeriod: '1209600'
      VisibilityTimeout: '20'
      ReceiveMessageWaitTimeSeconds: '5'
      QueueName: queue1

  DeadLetterQueue:
    Type: AWS::SQS::Queue

  QueuePolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          Action: sqs:*
          Principal:
            AWS: !Ref 'AWS::AccountId'
          Effect: Allow
      Queues:
        - !Ref Queue
        - !Ref DeadLetterQueue

Outputs:

  QueueURL:
    Description: URL of the queue
    Value: !Ref 'Queue'

  QueueARN:
    Description: ARN of the queue
    Value: !GetAtt 'Queue.Arn'

  DeadLetterQueueURL:
    Description: URL of the dead letter queue
    Value: !Ref 'DeadLetterQueue'

  DeadLetterQueueARN:
    Description: ARN of the dead letter queue
    Value: !GetAtt 'DeadLetterQueue.Arn'

The output for the stack will show the URLs and ARNs for the created queue resources.