PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/branches/v2.1.0/library/Microsoft/WindowsAzure/Storage/Queue.php

#
PHP | 582 lines | 312 code | 58 blank | 212 comment | 86 complexity | 7afdb4d1c3942ed2ba52e165ca27f839 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Copyright (c) 2009 - 2010, RealDolmen
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of RealDolmen nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * @category Microsoft
  29. * @package Microsoft_WindowsAzure
  30. * @subpackage Storage
  31. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  32. * @license http://todo name_todo
  33. * @version $Id: Blob.php 24241 2009-07-22 09:43:13Z unknown $
  34. */
  35. /**
  36. * @see Microsoft_WindowsAzure_Credentials_SharedKey
  37. */
  38. require_once 'Microsoft/WindowsAzure/Credentials/SharedKey.php';
  39. /**
  40. * @see Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract
  41. */
  42. require_once 'Microsoft/WindowsAzure/RetryPolicy/RetryPolicyAbstract.php';
  43. /**
  44. * @see Microsoft_Http_Client
  45. */
  46. require_once 'Microsoft/Http/Client.php';
  47. /**
  48. * @see Microsoft_Http_Response
  49. */
  50. require_once 'Microsoft/Http/Response.php';
  51. /**
  52. * @see Microsoft_WindowsAzure_Storage
  53. */
  54. require_once 'Microsoft/WindowsAzure/Storage.php';
  55. /**
  56. * Microsoft_WindowsAzure_Storage_QueueInstance
  57. */
  58. require_once 'Microsoft/WindowsAzure/Storage/QueueInstance.php';
  59. /**
  60. * Microsoft_WindowsAzure_Storage_QueueMessage
  61. */
  62. require_once 'Microsoft/WindowsAzure/Storage/QueueMessage.php';
  63. /**
  64. * @see Microsoft_WindowsAzure_Exception
  65. */
  66. require_once 'Microsoft/WindowsAzure/Exception.php';
  67. /**
  68. * @category Microsoft
  69. * @package Microsoft_WindowsAzure
  70. * @subpackage Storage
  71. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  72. * @license http://phpazure.codeplex.com/license
  73. */
  74. class Microsoft_WindowsAzure_Storage_Queue extends Microsoft_WindowsAzure_Storage
  75. {
  76. /**
  77. * Maximal message size (in bytes)
  78. */
  79. const MAX_MESSAGE_SIZE = 8388608;
  80. /**
  81. * Maximal message ttl (in seconds)
  82. */
  83. const MAX_MESSAGE_TTL = 604800;
  84. /**
  85. * Creates a new Microsoft_WindowsAzure_Storage_Queue instance
  86. *
  87. * @param string $host Storage host name
  88. * @param string $accountName Account name for Windows Azure
  89. * @param string $accountKey Account key for Windows Azure
  90. * @param boolean $usePathStyleUri Use path-style URI's
  91. * @param Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
  92. */
  93. public function __construct($host = Microsoft_WindowsAzure_Storage::URL_DEV_QUEUE, $accountName = Microsoft_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_ACCOUNT, $accountKey = Microsoft_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_KEY, $usePathStyleUri = false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
  94. {
  95. parent::__construct($host, $accountName, $accountKey, $usePathStyleUri, $retryPolicy);
  96. // API version
  97. $this->_apiVersion = '2009-09-19';
  98. }
  99. /**
  100. * Check if a queue exists
  101. *
  102. * @param string $queueName Queue name
  103. * @return boolean
  104. */
  105. public function queueExists($queueName = '')
  106. {
  107. if ($queueName === '') {
  108. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  109. }
  110. if (!self::isValidQueueName($queueName)) {
  111. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  112. }
  113. // List queues
  114. $queues = $this->listQueues($queueName, 1);
  115. foreach ($queues as $queue) {
  116. if ($queue->Name == $queueName) {
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. /**
  123. * Create queue
  124. *
  125. * @param string $queueName Queue name
  126. * @param array $metadata Key/value pairs of meta data
  127. * @return object Queue properties
  128. * @throws Microsoft_WindowsAzure_Exception
  129. */
  130. public function createQueue($queueName = '', $metadata = array())
  131. {
  132. if ($queueName === '') {
  133. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  134. }
  135. if (!self::isValidQueueName($queueName)) {
  136. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  137. }
  138. // Create metadata headers
  139. $headers = array();
  140. $headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
  141. // Perform request
  142. $response = $this->_performRequest($queueName, '', Microsoft_Http_Client::PUT, $headers);
  143. if ($response->isSuccessful()) {
  144. return new Microsoft_WindowsAzure_Storage_QueueInstance(
  145. $queueName,
  146. $metadata
  147. );
  148. } else {
  149. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  150. }
  151. }
  152. /**
  153. * Create queue if it does not exist
  154. *
  155. * @param string $queueName Queue name
  156. * @param array $metadata Key/value pairs of meta data
  157. * @throws Microsoft_WindowsAzure_Exception
  158. */
  159. public function createQueueIfNotExists($queueName = '', $metadata = array())
  160. {
  161. if (!$this->queueExists($queueName)) {
  162. $this->createQueue($queueName, $metadata);
  163. }
  164. }
  165. /**
  166. * Get queue
  167. *
  168. * @param string $queueName Queue name
  169. * @return Microsoft_WindowsAzure_Storage_QueueInstance
  170. * @throws Microsoft_WindowsAzure_Exception
  171. */
  172. public function getQueue($queueName = '')
  173. {
  174. if ($queueName === '') {
  175. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  176. }
  177. if (!self::isValidQueueName($queueName)) {
  178. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  179. }
  180. // Perform request
  181. $response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::GET);
  182. if ($response->isSuccessful()) {
  183. // Parse metadata
  184. $metadata = $this->_parseMetadataHeaders($response->getHeaders());
  185. // Return queue
  186. $queue = new Microsoft_WindowsAzure_Storage_QueueInstance(
  187. $queueName,
  188. $metadata
  189. );
  190. $queue->ApproximateMessageCount = intval($response->getHeader('x-ms-approximate-message-count'));
  191. return $queue;
  192. } else {
  193. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  194. }
  195. }
  196. /**
  197. * Get queue metadata
  198. *
  199. * @param string $queueName Queue name
  200. * @return array Key/value pairs of meta data
  201. * @throws Microsoft_WindowsAzure_Exception
  202. */
  203. public function getQueueMetadata($queueName = '')
  204. {
  205. if ($queueName === '') {
  206. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  207. }
  208. if (!self::isValidQueueName($queueName)) {
  209. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  210. }
  211. return $this->getQueue($queueName)->Metadata;
  212. }
  213. /**
  214. * Set queue metadata
  215. *
  216. * 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.
  217. *
  218. * @param string $queueName Queue name
  219. * @param array $metadata Key/value pairs of meta data
  220. * @throws Microsoft_WindowsAzure_Exception
  221. */
  222. public function setQueueMetadata($queueName = '', $metadata = array())
  223. {
  224. if ($queueName === '') {
  225. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  226. }
  227. if (!self::isValidQueueName($queueName)) {
  228. throw new Microsoft_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. // Create metadata headers
  234. $headers = array();
  235. $headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
  236. // Perform request
  237. $response = $this->_performRequest($queueName, '?comp=metadata', Microsoft_Http_Client::PUT, $headers);
  238. if (!$response->isSuccessful()) {
  239. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  240. }
  241. }
  242. /**
  243. * Delete queue
  244. *
  245. * @param string $queueName Queue name
  246. * @throws Microsoft_WindowsAzure_Exception
  247. */
  248. public function deleteQueue($queueName = '')
  249. {
  250. if ($queueName === '') {
  251. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  252. }
  253. if (!self::isValidQueueName($queueName)) {
  254. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  255. }
  256. // Perform request
  257. $response = $this->_performRequest($queueName, '', Microsoft_Http_Client::DELETE);
  258. if (!$response->isSuccessful()) {
  259. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  260. }
  261. }
  262. /**
  263. * List queues
  264. *
  265. * @param string $prefix Optional. Filters the results to return only queues whose name begins with the specified prefix.
  266. * @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)
  267. * @param string $marker Optional string value that identifies the portion of the list to be returned with the next list operation.
  268. * @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')
  269. * @param int $currentResultCount Current result count (internal use)
  270. * @return array
  271. * @throws Microsoft_WindowsAzure_Exception
  272. */
  273. public function listQueues($prefix = null, $maxResults = null, $marker = null, $include = null, $currentResultCount = 0)
  274. {
  275. // Build query string
  276. $queryString = array('comp=list');
  277. if (!is_null($prefix)) {
  278. $queryString[] = 'prefix=' . $prefix;
  279. }
  280. if (!is_null($maxResults)) {
  281. $queryString[] = 'maxresults=' . $maxResults;
  282. }
  283. if (!is_null($marker)) {
  284. $queryString[] = 'marker=' . $marker;
  285. }
  286. if (!is_null($include)) {
  287. $queryString[] = 'include=' . $include;
  288. }
  289. $queryString = self::createQueryStringFromArray($queryString);
  290. // Perform request
  291. $response = $this->_performRequest('', $queryString, Microsoft_Http_Client::GET);
  292. if ($response->isSuccessful()) {
  293. $xmlQueues = $this->_parseResponse($response)->Queues->Queue;
  294. $xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
  295. $queues = array();
  296. if (!is_null($xmlQueues)) {
  297. for ($i = 0; $i < count($xmlQueues); $i++) {
  298. $queues[] = new Microsoft_WindowsAzure_Storage_QueueInstance(
  299. (string)$xmlQueues[$i]->Name,
  300. $this->_parseMetadataElement($xmlQueues[$i])
  301. );
  302. }
  303. }
  304. $currentResultCount = $currentResultCount + count($queues);
  305. if (!is_null($maxResults) && $currentResultCount < $maxResults) {
  306. if (!is_null($xmlMarker) && $xmlMarker != '') {
  307. $queues = array_merge($queues, $this->listQueues($prefix, $maxResults, $xmlMarker, $include, $currentResultCount));
  308. }
  309. }
  310. if (!is_null($maxResults) && count($queues) > $maxResults) {
  311. $queues = array_slice($queues, 0, $maxResults);
  312. }
  313. return $queues;
  314. } else {
  315. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  316. }
  317. }
  318. /**
  319. * Put message into queue
  320. *
  321. * @param string $queueName Queue name
  322. * @param string $message Message
  323. * @param int $ttl Message Time-To-Live (in seconds). Defaults to 7 days if the parameter is omitted.
  324. * @throws Microsoft_WindowsAzure_Exception
  325. */
  326. public function putMessage($queueName = '', $message = '', $ttl = null)
  327. {
  328. if ($queueName === '') {
  329. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  330. }
  331. if (!self::isValidQueueName($queueName)) {
  332. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  333. }
  334. if (strlen($message) > self::MAX_MESSAGE_SIZE) {
  335. throw new Microsoft_WindowsAzure_Exception('Message is too big. Message content should be < 8KB.');
  336. }
  337. if ($message == '') {
  338. throw new Microsoft_WindowsAzure_Exception('Message is not specified.');
  339. }
  340. if (!is_null($ttl) && ($ttl <= 0 || $ttl > self::MAX_MESSAGE_SIZE)) {
  341. throw new Microsoft_WindowsAzure_Exception('Message TTL is invalid. Maximal TTL is 7 days (' . self::MAX_MESSAGE_SIZE . ' seconds) and should be greater than zero.');
  342. }
  343. // Build query string
  344. $queryString = array();
  345. if (!is_null($ttl)) {
  346. $queryString[] = 'messagettl=' . $ttl;
  347. }
  348. $queryString = self::createQueryStringFromArray($queryString);
  349. // Build body
  350. $rawData = '';
  351. $rawData .= '<QueueMessage>';
  352. $rawData .= ' <MessageText>' . base64_encode($message) . '</MessageText>';
  353. $rawData .= '</QueueMessage>';
  354. // Perform request
  355. $response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::POST, array(), false, $rawData);
  356. if (!$response->isSuccessful()) {
  357. throw new Microsoft_WindowsAzure_Exception('Error putting message into queue.');
  358. }
  359. }
  360. /**
  361. * Get queue messages
  362. *
  363. * @param string $queueName Queue name
  364. * @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.
  365. * @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.
  366. * @param string $peek Peek only?
  367. * @return array
  368. * @throws Microsoft_WindowsAzure_Exception
  369. */
  370. public function getMessages($queueName = '', $numOfMessages = 1, $visibilityTimeout = null, $peek = false)
  371. {
  372. if ($queueName === '') {
  373. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  374. }
  375. if (!self::isValidQueueName($queueName)) {
  376. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  377. }
  378. if ($numOfMessages < 1 || $numOfMessages > 32 || intval($numOfMessages) != $numOfMessages) {
  379. throw new Microsoft_WindowsAzure_Exception('Invalid number of messages to retrieve.');
  380. }
  381. if (!is_null($visibilityTimeout) && ($visibilityTimeout <= 0 || $visibilityTimeout > 7200)) {
  382. throw new Microsoft_WindowsAzure_Exception('Visibility timeout is invalid. Maximum value is 2 hours (7200 seconds) and should be greater than zero.');
  383. }
  384. // Build query string
  385. $queryString = array();
  386. if ($peek) {
  387. $queryString[] = 'peekonly=true';
  388. }
  389. if ($numOfMessages > 1) {
  390. $queryString[] = 'numofmessages=' . $numOfMessages;
  391. }
  392. if (!$peek && !is_null($visibilityTimeout)) {
  393. $queryString[] = 'visibilitytimeout=' . $visibilityTimeout;
  394. }
  395. $queryString = self::createQueryStringFromArray($queryString);
  396. // Perform request
  397. $response = $this->_performRequest($queueName . '/messages', $queryString, Microsoft_Http_Client::GET);
  398. if ($response->isSuccessful()) {
  399. // Parse results
  400. $result = $this->_parseResponse($response);
  401. if (!$result) {
  402. return array();
  403. }
  404. $xmlMessages = null;
  405. if (count($result->QueueMessage) > 1) {
  406. $xmlMessages = $result->QueueMessage;
  407. } else {
  408. $xmlMessages = array($result->QueueMessage);
  409. }
  410. $messages = array();
  411. for ($i = 0; $i < count($xmlMessages); $i++) {
  412. $messages[] = new Microsoft_WindowsAzure_Storage_QueueMessage(
  413. (string)$xmlMessages[$i]->MessageId,
  414. (string)$xmlMessages[$i]->InsertionTime,
  415. (string)$xmlMessages[$i]->ExpirationTime,
  416. ($peek ? '' : (string)$xmlMessages[$i]->PopReceipt),
  417. ($peek ? '' : (string)$xmlMessages[$i]->TimeNextVisible),
  418. (string)$xmlMessages[$i]->DequeueCount,
  419. base64_decode((string)$xmlMessages[$i]->MessageText)
  420. );
  421. }
  422. return $messages;
  423. } else {
  424. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  425. }
  426. }
  427. /**
  428. * Peek queue messages
  429. *
  430. * @param string $queueName Queue name
  431. * @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.
  432. * @return array
  433. * @throws Microsoft_WindowsAzure_Exception
  434. */
  435. public function peekMessages($queueName = '', $numOfMessages = 1)
  436. {
  437. return $this->getMessages($queueName, $numOfMessages, null, true);
  438. }
  439. /**
  440. * Clear queue messages
  441. *
  442. * @param string $queueName Queue name
  443. * @throws Microsoft_WindowsAzure_Exception
  444. */
  445. public function clearMessages($queueName = '')
  446. {
  447. if ($queueName === '') {
  448. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  449. }
  450. if (!self::isValidQueueName($queueName)) {
  451. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  452. }
  453. // Perform request
  454. $response = $this->_performRequest($queueName . '/messages', '', Microsoft_Http_Client::DELETE);
  455. if (!$response->isSuccessful()) {
  456. throw new Microsoft_WindowsAzure_Exception('Error clearing messages from queue.');
  457. }
  458. }
  459. /**
  460. * Delete queue message
  461. *
  462. * @param string $queueName Queue name
  463. * @param Microsoft_WindowsAzure_Storage_QueueMessage $message Message to delete from queue. A message retrieved using "peekMessages" can NOT be deleted!
  464. * @throws Microsoft_WindowsAzure_Exception
  465. */
  466. public function deleteMessage($queueName = '', Microsoft_WindowsAzure_Storage_QueueMessage $message)
  467. {
  468. if ($queueName === '') {
  469. throw new Microsoft_WindowsAzure_Exception('Queue name is not specified.');
  470. }
  471. if (!self::isValidQueueName($queueName)) {
  472. throw new Microsoft_WindowsAzure_Exception('Queue name does not adhere to queue naming conventions. See http://msdn.microsoft.com/en-us/library/dd179349.aspx for more information.');
  473. }
  474. if ($message->PopReceipt == '') {
  475. throw new Microsoft_WindowsAzure_Exception('A message retrieved using "peekMessages" can NOT be deleted! Use "getMessages" instead.');
  476. }
  477. // Perform request
  478. $response = $this->_performRequest($queueName . '/messages/' . $message->MessageId, '?popreceipt=' . $message->PopReceipt, Microsoft_Http_Client::DELETE);
  479. if (!$response->isSuccessful()) {
  480. throw new Microsoft_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
  481. }
  482. }
  483. /**
  484. * Is valid queue name?
  485. *
  486. * @param string $queueName Queue name
  487. * @return boolean
  488. */
  489. public static function isValidQueueName($queueName = '')
  490. {
  491. if (preg_match("/^[a-z0-9][a-z0-9-]*$/", $queueName) === 0) {
  492. return false;
  493. }
  494. if (strpos($queueName, '--') !== false) {
  495. return false;
  496. }
  497. if (strtolower($queueName) != $queueName) {
  498. return false;
  499. }
  500. if (strlen($queueName) < 3 || strlen($queueName) > 63) {
  501. return false;
  502. }
  503. if (substr($queueName, -1) == '-') {
  504. return false;
  505. }
  506. return true;
  507. }
  508. /**
  509. * Get error message from Microsoft_Http_Response
  510. *
  511. * @param Microsoft_Http_Response $response Repsonse
  512. * @param string $alternativeError Alternative error message
  513. * @return string
  514. */
  515. protected function _getErrorMessage(Microsoft_Http_Response $response, $alternativeError = 'Unknown error.')
  516. {
  517. $response = $this->_parseResponse($response);
  518. if ($response && $response->Message) {
  519. return (string)$response->Message;
  520. } else {
  521. return $alternativeError;
  522. }
  523. }
  524. }