|
|
@@ -67,9 +67,17 @@ class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract
|
|
|
*/
|
|
|
protected $_sqsSignatureMethod = 'HmacSHA256';
|
|
|
|
|
|
+ protected $_sqsEndpoints = 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');
|
|
|
/**
|
|
|
* Constructor
|
|
|
*
|
|
|
+ * 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.
|
|
|
+ *
|
|
|
* @param string $accessKey
|
|
|
* @param string $secretKey
|
|
|
* @param string $region
|
|
|
@@ -77,9 +85,78 @@ class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract
|
|
|
public function __construct($accessKey = null, $secretKey = null, $region = null)
|
|
|
{
|
|
|
parent::__construct($accessKey, $secretKey, $region);
|
|
|
+
|
|
|
+ if (null !== $region) {
|
|
|
+ $this->_setEndpoint($region);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Set SQS endpoint
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ *
|
|
|
+ * @param string $region region
|
|
|
+ * @throws Zend_Service_Amazon_Sqs_Exception
|
|
|
+ */
|
|
|
+ protected function _setEndpoint($region)
|
|
|
+ {
|
|
|
+ if (array_key_exists($region, $this->_sqsEndpoints)) {
|
|
|
+ $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
|
|
|
+ } else {
|
|
|
+ throw new Zend_Service_Amazon_Sqs_Exception('Invalid SQS region specified.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set SQS endpoint
|
|
|
+ *
|
|
|
+ * You can set SQS to on of the build-in regions. If the region does not exsist it will be added.
|
|
|
+ *
|
|
|
+ * @param string $region region
|
|
|
+ * @throws Zend_Service_Amazon_Sqs_Exception
|
|
|
+ */
|
|
|
+ public function setEndpoint($region)
|
|
|
+ {
|
|
|
+ if (!empty($region)) {
|
|
|
+ if (array_key_exists($region, $this->_sqsEndpoints)) {
|
|
|
+ $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
|
|
|
+ } else {
|
|
|
+ $this->_sqsEndpoints[$region] = "sqs.$region.amazonaws.com";
|
|
|
+ $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Zend_Service_Amazon_Sqs_Exception('Empty region specified.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get the SQS endpoint
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getEndpoint()
|
|
|
+ {
|
|
|
+ return $this->_sqsEndpoint;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get possible SQS endpoints
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ *
|
|
|
+ * @param string $region region
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getEndpoints()
|
|
|
+ {
|
|
|
+ return $this->_sqsEndpoints;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Create a new queue
|
|
|
*
|
|
|
* Visibility timeout is how long a message is left in the queue "invisible"
|