Class for connecting to the Amazon Simple Queue Service (SQS)

category Zend
package Zend_Service
subpackage Amazon_Sqs
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
see Amazon Simple Queue Service
inherited_from \Zend_Service_Amazon_Abstract

 Methods

Constructor

__construct(string $accessKey = null, string $secretKey = null, string $region = null

The default region is us-east-1. Use the region to set it to one of the regions that is build-in into ZF. To add a new AWS region use the setEndpoint() method.

inherited_from \Zend_Service_Amazon_Abstract::__construct()

Parameters

$accessKey

string

$secretKey

string

$region

string

Create Amazon client.

__construct($accessKey = null, $secretKey = null) : void
Inherited

Parameters

$accessKey

$secretKey

Return the approximate number of messages in the queue

count(string $queue_url) : integer

Parameters

$queue_url

string

Queue URL

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

integer

Create a new queue

create(string $queue_name, integer $timeout = null) : string | boolean

Visibility timeout is how long a message is left in the queue "invisible" to other readers. If the message is acknowleged (deleted) before the timeout, then the message is deleted. However, if the timeout expires then the message will be made available to other queue readers.

Parameters

$queue_name

string

queue name

$timeout

integer

default visibility timeout

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

stringboolean

Delete a queue and all of it's messages

delete(string $queue_url) : boolean

Returns false if the queue is not found, true if the queue exists

Parameters

$queue_url

string

queue URL

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

boolean

Delete a message from the queue

deleteMessage(string $queue_url, string $handle) : boolean

Returns true if the message is deleted, false if the deletion is unsuccessful.

Parameters

$queue_url

string

Queue URL

$handle

string

Message handle as returned by SQS

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

boolean

Get the attributes for the queue

getAttribute(string $queue_url, string $attribute = 'All') : string

Parameters

$queue_url

string

Queue URL

$attribute

string

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

string

Get the SQS endpoint

getEndpoint() : string

Returns

string

Get possible SQS endpoints

getEndpoints() : array

Since there is not an SQS webserive to get all possible endpoints, a hardcoded list is available. For the actual region list please check: http://docs.amazonwebservices.com/AWSSimpleQueueService/2009-02-01/APIReference/index.html?QueueServiceWsdlArticle.html

Returns

array

Gets the HTTP client object.

getHttpClient() : \Zend_Http_Client
InheritedStatic

Returns

\Zend_Http_Client

Get an array of all available queues

getQueues() : array

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

array

Get messages in the queue

receive(string $queue_url, integer $max_messages = null, integer $timeout = null) : array

Parameters

$queue_url

string

Queue name

$max_messages

integer

Maximum number of messages to return

$timeout

integer

Visibility timeout for these messages

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

array

Send a message to the queue

send(string $queue_url, string $message) : string

Parameters

$queue_url

string

Queue URL

$message

string

Message to send to the queue

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Returns

stringMessage ID

Set SQS endpoint

setEndpoint(string $region) 

You can set SQS to on of the build-in regions. If the region does not exsist it will be added.

Parameters

$region

string

region

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Sets the HTTP client object to use for retrieving the feeds. If none is set, the default Zend_Http_Client will be used.

setHttpClient(\Zend_Http_Client $httpClient) 
InheritedStatic

Parameters

$httpClient

\Zend_Http_Client

Set the keys to use when accessing SQS.

setKeys($accessKey, $secretKey) : void
InheritedStatic

Parameters

$accessKey

$secretKey

Method to fetch the Access Key

_getAccessKey() : string
Inherited

Returns

string

Method to fetch the Secret AWS Key

_getSecretKey() : string
Inherited

Returns

string

Set SQS endpoint

_setEndpoint(string $region) 

Checks and sets endpoint if region exists in $_sqsEndpoints. If a new SQS region is added by amazon, please use the setEndpoint function to set it.

Parameters

$region

string

region

Exceptions

\Zend_Service_Amazon_Sqs_Exception

Computes the RFC 2104-compliant HMAC signature for request parameters

_signParameters(string $queue_url, array $paramaters) : string

This implements the Amazon Web Services signature, as per the following specification:

  1. Sort all request parameters (including SignatureVersion and excluding Signature, the value of which is being created), ignoring case.

  2. Iterate over the sorted list and append the parameter name (in its original case) and then its value. Do not URL-encode the parameter values before constructing this string. Do not use any separator characters when appending strings.

Parameters

$queue_url

string

Queue URL

$paramaters

Returns

stringthe signed data.

Adds required authentication and version parameters to an array of parameters

addRequiredParameters(string $queue_url, array $parameters) : array

The required parameters are:

  • AWSAccessKey
  • SignatureVersion
  • Timestamp
  • Version and
  • Signature

If a required parameter is already set in the $parameters array, it is overwritten.

Parameters

$queue_url

string

Queue URL

$parameters

array

the array to which to add the required parameters.

Returns

array

Make a request to Amazon SQS

_makeRequest($queue_url, string $action, array $params = array()) : \SimpleXMLElement

Parameters

$queue_url

$action

string

SQS action

$params

array

Returns

\SimpleXMLElement

 Properties

 

Amazon Access Key

$_accessKey : string

Default

 

Amazon Access Key

$_defaultAccessKey : string

Default

null
Static
 

Amazon Secret Key

$_defaultSecretKey : string

Default

null
Static
 

HTTP Client used to query all web services

$_httpClient : \Zend_Http_Client

Default

null
Static
 

Amazon Secret Key

$_secretKey : string

Default

 

The API version to use

$_sqsApiVersion 

Default

'2009-02-01'
 

HTTP end point for the Amazon SQS service

$_sqsEndpoint 

Default

'queue.amazonaws.com'
 

$_sqsEndpoints

$_sqsEndpoints 

Default

array('us-east-1' => 'sqs.us-east-1.amazonaws.com', 'us-west-1' => 'sqs.us-west-1.amazonaws.com', 'eu-west-1' => 'sqs.eu-west-1.amazonaws.com', 'ap-southeast-1' => 'sqs.ap-southeast-1.amazonaws.com', 'ap-northeast-1' => 'sqs.ap-northeast-1.amazonaws.com')
 

Signature Encoding Method

$_sqsSignatureMethod 

Default

'HmacSHA256'
 

Signature Version

$_sqsSignatureVersion 

Default

'2'

 Constants

 

Default timeout for createQueue() function

CREATE_TIMEOUT_DEFAULT = 30