EC2 instance using Amazon SQS queues


Hits: 4425  

Amazon Simple Queue Service (Amazon SQS) offers a reliable, highly scalable, hosted queue for storing messages. Amazon SQS can be used to applications that perform different tasks, without losing messages. Amazon SQS enables users to build an automated workflow.

Amazon Elastic Compute Cloud (EC2) is a web service that provides resizable compute capacity in the cloud. Amazon EC2 can be used for building applications that start small but can scale up rapidly as demand increases (Auto Scaling).

Amazon EC2 Features:

a) Increase or decrease capacity within minutes.
b) Make one, hundreds, or even thousands of server instances simultaneously.
c) Web Service API to control the scaling of instances depending on needs.
d) Pay only for what you use (Pay Per Use) pricing model.

SQS

Features of Amazon SQS:

a) Single Amazon SQS queue can be shared by multiple servers simultaneously.
b) Server that is processing a message can prevent other servers from processing the same message at the same time using temporarily “locking” a message. The server can specify the amount of time the message is locked. When the server is done processing the message, it should delete the message. If the server fails while processing the message, another server can get the message after the lockout period.

AWS-SQS-EC2-S3

Pipeline processing with Amazon SQS:

Pipeline processing with Amazon SQS

a) Flexibility: Large monolithic server can be divided into multiple smaller servers without impacting the current system.

b) Piecemeal upgrades: Individual sub-components can be taken offline / upgraded without bringing the entire system down.

c) Tolerance to failures: Amazon SQS isolates sub-components from each other so the failure of one component does not impact the rest.


<?php

require_once('sqs.client.php');

define('AWS_ACCESS_KEY_ID''<access key>');

define('AWS_SECRET_ACCESS_KEY''<secret key>');

define('SQS_ENDPOINT''http://queue.amazonaws.com');

define('SQS_TEST_QUEUE''SQS-Queue-SVNLabs');

define('SQS_TEST_MESSAGE''Welcome to SQS.');

try

{

   $q = new SQSClient(AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYSQS_ENDPOINT);

   // create Queue

   
$result $q->CreateQueue(SQS_TEST_QUEUE);

   

   
// list Queue

   
$result $q->ListQueues();

   // send message to Queue

   
$messageId $q->SendMessage(urlencode(SQS_TEST_MESSAGE));

   // receive message from Queue

   
$messages $q->ReceiveMessage();

}

catch(
Exception $e)

{

    echo 
'Exception occurred: '$e->getMessage(), "\n<br />\n";

}

?>    

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

Leave a Reply

Your email address will not be published.

*