13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service |
16 * @package Zend_Service |
17 * @subpackage Amazon_Sqs |
17 * @subpackage Amazon_Sqs |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Sqs.php 22984 2010-09-21 02:52:48Z matthew $ |
20 * @version $Id: Sqs.php 25024 2012-07-30 15:08:15Z rob $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_Service_Amazon_Abstract |
24 * @see Zend_Service_Amazon_Abstract |
25 */ |
25 */ |
34 * Class for connecting to the Amazon Simple Queue Service (SQS) |
34 * Class for connecting to the Amazon Simple Queue Service (SQS) |
35 * |
35 * |
36 * @category Zend |
36 * @category Zend |
37 * @package Zend_Service |
37 * @package Zend_Service |
38 * @subpackage Amazon_Sqs |
38 * @subpackage Amazon_Sqs |
39 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
39 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
40 * @license http://framework.zend.com/license/new-bsd New BSD License |
40 * @license http://framework.zend.com/license/new-bsd New BSD License |
41 * @see http://aws.amazon.com/sqs/ Amazon Simple Queue Service |
41 * @see http://aws.amazon.com/sqs/ Amazon Simple Queue Service |
42 */ |
42 */ |
43 class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract |
43 class Zend_Service_Amazon_Sqs extends Zend_Service_Amazon_Abstract |
44 { |
44 { |
65 /** |
65 /** |
66 * Signature Encoding Method |
66 * Signature Encoding Method |
67 */ |
67 */ |
68 protected $_sqsSignatureMethod = 'HmacSHA256'; |
68 protected $_sqsSignatureMethod = 'HmacSHA256'; |
69 |
69 |
|
70 protected $_sqsEndpoints = array('us-east-1' => 'sqs.us-east-1.amazonaws.com', |
|
71 'us-west-1' => 'sqs.us-west-1.amazonaws.com', |
|
72 'eu-west-1' => 'sqs.eu-west-1.amazonaws.com', |
|
73 'ap-southeast-1' => 'sqs.ap-southeast-1.amazonaws.com', |
|
74 'ap-northeast-1' => 'sqs.ap-northeast-1.amazonaws.com'); |
70 /** |
75 /** |
71 * Constructor |
76 * Constructor |
|
77 * |
|
78 * The default region is us-east-1. Use the region to set it to one of the regions that is build-in into ZF. |
|
79 * To add a new AWS region use the setEndpoint() method. |
72 * |
80 * |
73 * @param string $accessKey |
81 * @param string $accessKey |
74 * @param string $secretKey |
82 * @param string $secretKey |
75 * @param string $region |
83 * @param string $region |
76 */ |
84 */ |
77 public function __construct($accessKey = null, $secretKey = null, $region = null) |
85 public function __construct($accessKey = null, $secretKey = null, $region = null) |
78 { |
86 { |
79 parent::__construct($accessKey, $secretKey, $region); |
87 parent::__construct($accessKey, $secretKey, $region); |
80 } |
88 |
81 |
89 if (null !== $region) { |
|
90 $this->_setEndpoint($region); |
|
91 } |
|
92 } |
|
93 |
|
94 /** |
|
95 * Set SQS endpoint |
|
96 * |
|
97 * Checks and sets endpoint if region exists in $_sqsEndpoints. If a new SQS region is added by amazon, |
|
98 * please use the setEndpoint function to set it. |
|
99 * |
|
100 * @param string $region region |
|
101 * @throws Zend_Service_Amazon_Sqs_Exception |
|
102 */ |
|
103 protected function _setEndpoint($region) |
|
104 { |
|
105 if (array_key_exists($region, $this->_sqsEndpoints)) { |
|
106 $this->_sqsEndpoint = $this->_sqsEndpoints[$region]; |
|
107 } else { |
|
108 throw new Zend_Service_Amazon_Sqs_Exception('Invalid SQS region specified.'); |
|
109 } |
|
110 } |
|
111 |
|
112 /** |
|
113 * Set SQS endpoint |
|
114 * |
|
115 * You can set SQS to on of the build-in regions. If the region does not exsist it will be added. |
|
116 * |
|
117 * @param string $region region |
|
118 * @throws Zend_Service_Amazon_Sqs_Exception |
|
119 */ |
|
120 public function setEndpoint($region) |
|
121 { |
|
122 if (!empty($region)) { |
|
123 if (array_key_exists($region, $this->_sqsEndpoints)) { |
|
124 $this->_sqsEndpoint = $this->_sqsEndpoints[$region]; |
|
125 } else { |
|
126 $this->_sqsEndpoints[$region] = "sqs.$region.amazonaws.com"; |
|
127 $this->_sqsEndpoint = $this->_sqsEndpoints[$region]; |
|
128 } |
|
129 } else { |
|
130 throw new Zend_Service_Amazon_Sqs_Exception('Empty region specified.'); |
|
131 } |
|
132 } |
|
133 |
|
134 /** |
|
135 * Get the SQS endpoint |
|
136 * |
|
137 * @return string |
|
138 */ |
|
139 public function getEndpoint() |
|
140 { |
|
141 return $this->_sqsEndpoint; |
|
142 } |
|
143 |
|
144 /** |
|
145 * Get possible SQS endpoints |
|
146 * |
|
147 * Since there is not an SQS webserive to get all possible endpoints, a hardcoded list is available. |
|
148 * For the actual region list please check: |
|
149 * http://docs.amazonwebservices.com/AWSSimpleQueueService/2009-02-01/APIReference/index.html?QueueServiceWsdlArticle.html |
|
150 * |
|
151 * @param string $region region |
|
152 * @return array |
|
153 */ |
|
154 public function getEndpoints() |
|
155 { |
|
156 return $this->_sqsEndpoints; |
|
157 } |
|
158 |
82 /** |
159 /** |
83 * Create a new queue |
160 * Create a new queue |
84 * |
161 * |
85 * Visibility timeout is how long a message is left in the queue "invisible" |
162 * Visibility timeout is how long a message is left in the queue "invisible" |
86 * to other readers. If the message is acknowleged (deleted) before the |
163 * to other readers. If the message is acknowleged (deleted) before the |
317 || empty($result->GetQueueAttributesResult->Attribute) |
394 || empty($result->GetQueueAttributesResult->Attribute) |
318 ) { |
395 ) { |
319 require_once 'Zend/Service/Amazon/Sqs/Exception.php'; |
396 require_once 'Zend/Service/Amazon/Sqs/Exception.php'; |
320 throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code); |
397 throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code); |
321 } |
398 } |
322 |
399 |
323 if(count($result->GetQueueAttributesResult->Attribute) > 1) { |
400 if(count($result->GetQueueAttributesResult->Attribute) > 1) { |
324 $attr_result = array(); |
401 $attr_result = array(); |
325 foreach($result->GetQueueAttributesResult->Attribute as $attribute) { |
402 foreach($result->GetQueueAttributesResult->Attribute as $attribute) { |
326 $attr_result[(string)$attribute->Name] = (string)$attribute->Value; |
403 $attr_result[(string)$attribute->Name] = (string)$attribute->Value; |
327 } |
404 } |