PageRenderTime 55ms CodeModel.GetById 38ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Zend/Service/WindowsAzure/Storage/Queue.php

http://grupal.googlecode.com/
PHP | 592 lines | 346 code | 55 blank | 191 comment | 86 complexity | 5d565412c389b32edf25c18ad5de011b MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Service_WindowsAzure
 17 * @subpackage Storage
 18 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://todo     name_todo
 20 * @version    $Id: Queue.php 24593 2012-01-05 20:35:02Z matthew $
 21 */
 22
 23/**
 24 * see Zend_Service_WindowsAzure_Storage
 25 */
 26require_once 'Zend/Service/WindowsAzure/Storage.php';
 27
 28/**
 29 * @see Zend_Service_WindowsAzure_Storage_QueueInstance
 30 */
 31require_once 'Zend/Service/WindowsAzure/Storage/QueueInstance.php';
 32
 33/**
 34 * @see Zend_Service_WindowsAzure_Storage_QueueMessage
 35 */
 36require_once 'Zend/Service/WindowsAzure/Storage/QueueMessage.php';
 37
 38/**
 39 * @category   Zend
 40 * @package    Zend_Service_WindowsAzure
 41 * @subpackage Storage
 42 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 43 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 44 */
 45class Zend_Service_WindowsAzure_Storage_Queue extends Zend_Service_WindowsAzure_Storage
 46{
 47	/**
 48	 * Maximal message size (in bytes)
 49	 */
 50	const MAX_MESSAGE_SIZE = 8388608;
 51	
 52	/**
 53	 * Maximal message ttl (in seconds)
 54	 */
 55	const MAX_MESSAGE_TTL = 604800;
 56	
 57	/**
 58	 * Creates a new Zend_Service_WindowsAzure_Storage_Queue instance
 59	 *
 60	 * @param string $host Storage host name
 61	 * @param string $accountName Account name for Windows Azure
 62	 * @param string $accountKey Account key for Windows Azure
 63	 * @param boolean $usePathStyleUri Use path-style URI's
 64	 * @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
 65	 */
 66	public function __construct($host = Zend_Service_WindowsAzure_Storage::URL_DEV_QUEUE, $accountName = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_ACCOUNT, $accountKey = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_KEY, $usePathStyleUri = false, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
 67	{
 68		parent::__construct($host, $accountName, $accountKey, $usePathStyleUri, $retryPolicy);
 69		
 70		// API version
 71		$this->_apiVersion = '2009-09-19';
 72	}
 73	
 74	/**
 75	 * Check if a queue exists
 76	 * 
 77	 * @param string $queueName Queue name
 78	 * @return boolean
 79	 */
 80	public function queueExists($queueName = '')
 81	{
 82		if ($queueName === '') {
 83			require_once 'Zend/Service/WindowsAzure/Exception.php';
 84			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
 85		}
 86		if (!self::isValidQueueName($queueName)) {
 87			require_once 'Zend/Service/WindowsAzure/Exception.php';
 88		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
 89		}
 90			
 91		// List queues
 92        $queues = $this->listQueues($queueName, 1);
 93        foreach ($queues as $queue) {
 94            if ($queue->Name == $queueName) {
 95                return true;
 96            }
 97        }
 98        
 99        return false;
100	}
101	
102	/**
103	 * Create queue
104	 *
105	 * @param string $queueName Queue name
106	 * @param array  $metadata  Key/value pairs of meta data
107	 * @return object Queue properties
108	 * @throws Zend_Service_WindowsAzure_Exception
109	 */
110	public function createQueue($queueName = '', $metadata = array())
111	{
112		if ($queueName === '') {
113			require_once 'Zend/Service/WindowsAzure/Exception.php';
114			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
115		}
116		if (!self::isValidQueueName($queueName)) {
117			require_once 'Zend/Service/WindowsAzure/Exception.php';
118		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
119		}
120			
121		// Create metadata headers
122		$headers = array();
123		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata)); 
124		
125		// Perform request
126		$response = $this->_performRequest($queueName, '', Zend_Http_Client::PUT, $headers);	
127		if ($response->isSuccessful()) {
128			
129		    return new Zend_Service_WindowsAzure_Storage_QueueInstance(
130		        $queueName,
131		        $metadata
132		    );
133		} else {
134			require_once 'Zend/Service/WindowsAzure/Exception.php';
135			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
136		}
137	}
138	
139	/**
140	 * Create queue if it does not exist
141	 *
142	 * @param string $queueName Queue name
143	 * @param array  $metadata  Key/value pairs of meta data
144	 * @throws Zend_Service_WindowsAzure_Exception
145	 */
146	public function createQueueIfNotExists($queueName = '', $metadata = array())
147	{
148		if (!$this->queueExists($queueName)) {
149			$this->createQueue($queueName, $metadata);
150		}
151	}
152	
153	/**
154	 * Get queue
155	 * 
156	 * @param string $queueName  Queue name
157	 * @return Zend_Service_WindowsAzure_Storage_QueueInstance
158	 * @throws Zend_Service_WindowsAzure_Exception
159	 */
160	public function getQueue($queueName = '')
161	{
162		if ($queueName === '') {
163			require_once 'Zend/Service/WindowsAzure/Exception.php';
164			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
165		}
166		if (!self::isValidQueueName($queueName)) {
167			require_once 'Zend/Service/WindowsAzure/Exception.php';
168		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
169		}
170		    
171		// Perform request
172		$response = $this->_performRequest($queueName, '?comp=metadata', Zend_Http_Client::GET);	
173		if ($response->isSuccessful()) {
174		    // Parse metadata
175		    $metadata = $this->_parseMetadataHeaders($response->getHeaders());
176			
177		    // Return queue
178		    $queue = new Zend_Service_WindowsAzure_Storage_QueueInstance(
179		        $queueName,
180		        $metadata
181		    );
182		    $queue->ApproximateMessageCount = intval($response->getHeader('x-ms-approximate-message-count'));
183		    return $queue;
184		} else {
185			require_once 'Zend/Service/WindowsAzure/Exception.php';
186		    throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
187		}
188	}
189	
190	/**
191	 * Get queue metadata
192	 * 
193	 * @param string $queueName  Queue name
194	 * @return array Key/value pairs of meta data
195	 * @throws Zend_Service_WindowsAzure_Exception
196	 */
197	public function getQueueMetadata($queueName = '')
198	{
199		if ($queueName === '') {
200			require_once 'Zend/Service/WindowsAzure/Exception.php';
201			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
202		}
203		if (!self::isValidQueueName($queueName)) {
204			require_once 'Zend/Service/WindowsAzure/Exception.php';
205		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
206		}
207			
208	    return $this->getQueue($queueName)->Metadata;
209	}
210	
211	/**
212	 * Set queue metadata
213	 * 
214	 * Calling the Set Queue Metadata operation overwrites all existing metadata that is associated with the queue. It's not possible to modify an individual name/value pair.
215	 *
216	 * @param string $queueName  Queue name
217	 * @param array  $metadata       Key/value pairs of meta data
218	 * @throws Zend_Service_WindowsAzure_Exception
219	 */
220	public function setQueueMetadata($queueName = '', $metadata = array())
221	{
222		if ($queueName === '') {
223			require_once 'Zend/Service/WindowsAzure/Exception.php';
224			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
225		}
226		if (!self::isValidQueueName($queueName)) {
227			require_once 'Zend/Service/WindowsAzure/Exception.php';
228		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
229		}
230		if (count($metadata) == 0) {
231		    return;
232		}
233		    
234		// Create metadata headers
235		$headers = array();
236		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata)); 
237		
238		// Perform request
239		$response = $this->_performRequest($queueName, '?comp=metadata', Zend_Http_Client::PUT, $headers);
240
241		if (!$response->isSuccessful()) {
242			require_once 'Zend/Service/WindowsAzure/Exception.php';
243			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
244		}
245	}
246	
247	/**
248	 * Delete queue
249	 *
250	 * @param string $queueName Queue name
251	 * @throws Zend_Service_WindowsAzure_Exception
252	 */
253	public function deleteQueue($queueName = '')
254	{
255		if ($queueName === '') {
256			require_once 'Zend/Service/WindowsAzure/Exception.php';
257			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
258		}
259		if (!self::isValidQueueName($queueName)) {
260			require_once 'Zend/Service/WindowsAzure/Exception.php';
261		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
262		}
263			
264		// Perform request
265		$response = $this->_performRequest($queueName, '', Zend_Http_Client::DELETE);
266		if (!$response->isSuccessful()) {
267			require_once 'Zend/Service/WindowsAzure/Exception.php';
268			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
269		}
270	}
271	
272	/**
273	 * List queues
274	 *
275	 * @param string $prefix     Optional. Filters the results to return only queues whose name begins with the specified prefix.
276	 * @param int    $maxResults Optional. Specifies the maximum number of queues to return per call to Azure storage. This does NOT affect list size returned by this function. (maximum: 5000)
277	 * @param string $marker     Optional string value that identifies the portion of the list to be returned with the next list operation.
278	 * @param string $include    Optional. Include this parameter to specify that the queue's metadata be returned as part of the response body. (allowed values: '', 'metadata')
279	 * @param int    $currentResultCount Current result count (internal use)
280	 * @return array
281	 * @throws Zend_Service_WindowsAzure_Exception
282	 */
283	public function listQueues($prefix = null, $maxResults = null, $marker = null, $include = null, $currentResultCount = 0)
284	{
285	    // Build query string
286		$queryString = array('comp=list');
287        if (!is_null($prefix)) {
288	        $queryString[] = 'prefix=' . $prefix;
289        }
290	    if (!is_null($maxResults)) {
291	        $queryString[] = 'maxresults=' . $maxResults;
292	    }
293	    if (!is_null($marker)) {
294	        $queryString[] = 'marker=' . $marker;
295	    }
296		if (!is_null($include)) {
297	        $queryString[] = 'include=' . $include;
298	    }
299	    $queryString = self::createQueryStringFromArray($queryString);
300	        
301		// Perform request
302		$response = $this->_performRequest('', $queryString, Zend_Http_Client::GET);	
303		if ($response->isSuccessful()) {
304			$xmlQueues = $this->_parseResponse($response)->Queues->Queue;
305			$xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
306
307			$queues = array();
308			if (!is_null($xmlQueues)) {
309				
310				for ($i = 0; $i < count($xmlQueues); $i++) {
311					$queues[] = new Zend_Service_WindowsAzure_Storage_QueueInstance(
312						(string)$xmlQueues[$i]->Name,
313						$this->_parseMetadataElement($xmlQueues[$i])
314					);
315				}
316			}
317			$currentResultCount = $currentResultCount + count($queues);
318			if (!is_null($maxResults) && $currentResultCount < $maxResults) {
319    			if (!is_null($xmlMarker) && $xmlMarker != '') {
320    			    $queues = array_merge($queues, $this->listQueues($prefix, $maxResults, $xmlMarker, $include, $currentResultCount));
321    			}
322			}
323			if (!is_null($maxResults) && count($queues) > $maxResults) {
324			    $queues = array_slice($queues, 0, $maxResults);
325			}
326			    
327			return $queues;
328		} else {
329			require_once 'Zend/Service/WindowsAzure/Exception.php';
330			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
331		}
332	}
333	
334	/**
335	 * Put message into queue
336	 *
337	 * @param string $queueName  Queue name
338	 * @param string $message    Message
339	 * @param int    $ttl        Message Time-To-Live (in seconds). Defaults to 7 days if the parameter is omitted.
340	 * @throws Zend_Service_WindowsAzure_Exception
341	 */
342	public function putMessage($queueName = '', $message = '', $ttl = null)
343	{
344		if ($queueName === '') {
345			require_once 'Zend/Service/WindowsAzure/Exception.php';
346			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
347		}
348		if (!self::isValidQueueName($queueName)) {
349			require_once 'Zend/Service/WindowsAzure/Exception.php';
350		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
351		}
352		if (strlen($message) > self::MAX_MESSAGE_SIZE) {
353			require_once 'Zend/Service/WindowsAzure/Exception.php';
354		    throw new Zend_Service_WindowsAzure_Exception('Message is too big. Message content should be < 8KB.');
355		}
356		if ($message == '') {
357			require_once 'Zend/Service/WindowsAzure/Exception.php';
358		    throw new Zend_Service_WindowsAzure_Exception('Message is not specified.');
359		}
360		if (!is_null($ttl) && ($ttl <= 0 || $ttl > self::MAX_MESSAGE_SIZE)) {
361			require_once 'Zend/Service/WindowsAzure/Exception.php';
362		    throw new Zend_Service_WindowsAzure_Exception('Message TTL is invalid. Maximal TTL is 7 days (' . self::MAX_MESSAGE_SIZE . ' seconds) and should be greater than zero.');
363		}
364		    
365	    // Build query string
366		$queryString = array();
367        if (!is_null($ttl)) {
368	        $queryString[] = 'messagettl=' . $ttl;
369        }
370	    $queryString = self::createQueryStringFromArray($queryString);
371	        
372	    // Build body
373	    $rawData = '';
374	    $rawData .= '<QueueMessage>';
375	    $rawData .= '    <MessageText>' . base64_encode($message) . '</MessageText>';
376	    $rawData .= '</QueueMessage>';
377	        
378		// Perform request
379		$response = $this->_performRequest($queueName . '/messages', $queryString, Zend_Http_Client::POST, array(), false, $rawData);
380
381		if (!$response->isSuccessful()) {
382			require_once 'Zend/Service/WindowsAzure/Exception.php';
383			throw new Zend_Service_WindowsAzure_Exception('Error putting message into queue.');
384		}
385	}
386	
387	/**
388	 * Get queue messages
389	 *
390	 * @param string $queueName         Queue name
391	 * @param string $numOfMessages     Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.
392	 * @param int    $visibilityTimeout Optional. An integer value that specifies the message's visibility timeout in seconds. The maximum value is 2 hours. The default message visibility timeout is 30 seconds.
393	 * @param string $peek              Peek only?
394	 * @return array
395	 * @throws Zend_Service_WindowsAzure_Exception
396	 */
397	public function getMessages($queueName = '', $numOfMessages = 1, $visibilityTimeout = null, $peek = false)
398	{
399		if ($queueName === '') {
400			require_once 'Zend/Service/WindowsAzure/Exception.php';
401			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
402		}
403		if (!self::isValidQueueName($queueName)) {
404			require_once 'Zend/Service/WindowsAzure/Exception.php';
405		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
406		}
407		if ($numOfMessages < 1 || $numOfMessages > 32 || intval($numOfMessages) != $numOfMessages) {
408			require_once 'Zend/Service/WindowsAzure/Exception.php';
409		    throw new Zend_Service_WindowsAzure_Exception('Invalid number of messages to retrieve.');
410		}
411		if (!is_null($visibilityTimeout) && ($visibilityTimeout <= 0 || $visibilityTimeout > 7200)) {
412			require_once 'Zend/Service/WindowsAzure/Exception.php';
413		    throw new Zend_Service_WindowsAzure_Exception('Visibility timeout is invalid. Maximum value is 2 hours (7200 seconds) and should be greater than zero.');
414		}
415		    
416	    // Build query string
417		$queryString = array();
418    	if ($peek) {
419    	    $queryString[] = 'peekonly=true';
420    	}
421    	if ($numOfMessages > 1) {
422	        $queryString[] = 'numofmessages=' . $numOfMessages;
423    	}
424    	if (!$peek && !is_null($visibilityTimeout)) {
425	        $queryString[] = 'visibilitytimeout=' . $visibilityTimeout;
426    	}   
427	    $queryString = self::createQueryStringFromArray($queryString);
428	        
429		// Perform request
430		$response = $this->_performRequest($queueName . '/messages', $queryString, Zend_Http_Client::GET);	
431		if ($response->isSuccessful()) {
432		    // Parse results
433			$result = $this->_parseResponse($response);
434		    if (!$result) {
435		        return array();
436		    }
437
438		    $xmlMessages = null;
439		    if (count($result->QueueMessage) > 1) {
440    		    $xmlMessages = $result->QueueMessage;
441    		} else {
442    		    $xmlMessages = array($result->QueueMessage);
443    		}
444			
445			$messages = array();
446			for ($i = 0; $i < count($xmlMessages); $i++) {
447				$messages[] = new Zend_Service_WindowsAzure_Storage_QueueMessage(
448					(string)$xmlMessages[$i]->MessageId,
449					(string)$xmlMessages[$i]->InsertionTime,
450					(string)$xmlMessages[$i]->ExpirationTime,
451					($peek ? '' : (string)$xmlMessages[$i]->PopReceipt),
452					($peek ? '' : (string)$xmlMessages[$i]->TimeNextVisible),
453					(string)$xmlMessages[$i]->DequeueCount,
454					base64_decode((string)$xmlMessages[$i]->MessageText)
455			    );
456			}
457			    
458			return $messages;
459		} else {
460			require_once 'Zend/Service/WindowsAzure/Exception.php';
461			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
462		}
463	}
464	
465	/**
466	 * Peek queue messages
467	 *
468	 * @param string $queueName         Queue name
469	 * @param string $numOfMessages     Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.
470	 * @return array
471	 * @throws Zend_Service_WindowsAzure_Exception
472	 */
473	public function peekMessages($queueName = '', $numOfMessages = 1)
474	{
475	    return $this->getMessages($queueName, $numOfMessages, null, true);
476	}
477	
478	/**
479	 * Checks to see if a given queue has messages
480	 *
481	 * @param string $queueName         Queue name
482	 * @return boolean
483	 * @throws Zend_Service_WindowsAzure_Exception
484	 */
485	public function hasMessages($queueName = '')
486	{
487		return count($this->peekMessages($queueName)) > 0;
488	}
489	
490	/**
491	 * Clear queue messages
492	 *
493	 * @param string $queueName         Queue name
494	 * @throws Zend_Service_WindowsAzure_Exception
495	 */
496	public function clearMessages($queueName = '')
497	{
498		if ($queueName === '') {
499			require_once 'Zend/Service/WindowsAzure/Exception.php';
500			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
501		}
502		if (!self::isValidQueueName($queueName)) {
503			require_once 'Zend/Service/WindowsAzure/Exception.php';
504		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
505		}
506
507		// Perform request
508		$response = $this->_performRequest($queueName . '/messages', '', Zend_Http_Client::DELETE);	
509		if (!$response->isSuccessful()) {
510			require_once 'Zend/Service/WindowsAzure/Exception.php';
511			throw new Zend_Service_WindowsAzure_Exception('Error clearing messages from queue.');
512		}
513	}
514	
515	/**
516	 * Delete queue message
517	 *
518	 * @param string $queueName Queue name
519	 * @param Zend_Service_WindowsAzure_Storage_QueueMessage $message Message to delete from queue. A message retrieved using "peekMessages" can NOT be deleted!
520	 * @throws Zend_Service_WindowsAzure_Exception
521	 */
522	public function deleteMessage($queueName = '', Zend_Service_WindowsAzure_Storage_QueueMessage $message)
523	{
524		if ($queueName === '') {
525			require_once 'Zend/Service/WindowsAzure/Exception.php';
526			throw new Zend_Service_WindowsAzure_Exception('Queue name is not specified.');
527		}
528		if (!self::isValidQueueName($queueName)) {
529			require_once 'Zend/Service/WindowsAzure/Exception.php';
530		    throw new Zend_Service_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
531		}
532		if ($message->PopReceipt == '') {
533			require_once 'Zend/Service/WindowsAzure/Exception.php';
534		    throw new Zend_Service_WindowsAzure_Exception('A message retrieved using "peekMessages" can NOT be deleted! Use "getMessages" instead.');
535		}
536
537		// Perform request
538		$response = $this->_performRequest($queueName . '/messages/' . $message->MessageId, '?popreceipt=' . urlencode($message->PopReceipt), Zend_Http_Client::DELETE);	
539		if (!$response->isSuccessful()) {
540			require_once 'Zend/Service/WindowsAzure/Exception.php';
541			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
542		}
543	}
544	
545	/**
546	 * Is valid queue name?
547	 *
548	 * @param string $queueName Queue name
549	 * @return boolean
550	 */
551    public static function isValidQueueName($queueName = '')
552    {
553        if (preg_match("/^[a-z0-9][a-z0-9-]*$/", $queueName) === 0) {
554            return false;
555        }
556    
557        if (strpos($queueName, '--') !== false) {
558            return false;
559        }
560    
561        if (strtolower($queueName) != $queueName) {
562            return false;
563        }
564    
565        if (strlen($queueName) < 3 || strlen($queueName) > 63) {
566            return false;
567        }
568            
569        if (substr($queueName, -1) == '-') {
570            return false;
571        }
572    
573        return true;
574    }
575    
576	/**
577	 * Get error message from Zend_Http_Response
578	 * 
579	 * @param Zend_Http_Response $response Repsonse
580	 * @param string $alternativeError Alternative error message
581	 * @return string
582	 */
583	protected function _getErrorMessage(Zend_Http_Response $response, $alternativeError = 'Unknown error.')
584	{
585		$response = $this->_parseResponse($response);
586		if ($response && $response->Message) {
587		    return (string)$response->Message;
588		} else {
589		    return $alternativeError;
590		}
591	}
592}