示例#1
2
 /**
  * @param string $name
  * @throws OperationException
  * @return array
  */
 protected function readQueueAttributes($name)
 {
     try {
         // grab url before in order to read attributes
         $queueUrl = $this->client->getQueueUrl(['QueueName' => $name]);
         $attributes = $this->client->getQueueAttributes(['QueueUrl' => $queueUrl->get('QueueUrl'), 'AttributeNames' => ['All']]);
         return $attributes->get('Attributes');
     } catch (\Exception $e) {
         throw new OperationException(sprintf('Cannot read attributes for queue "%s":%s', $name, $e->getMessage()), $e->getCode(), $e);
     }
 }
示例#2
1
 /**
  *
  * @return number
  */
 public function is_message($queue = '')
 {
     $result = $this->sqs->getQueueAttributes(['QueueUrl' => $queue, 'AttributeNames' => ['ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible', 'ApproximateNumberOfMessagesDelayed']]);
     $queuecount = 0;
     foreach ($result->get("Attributes") as $key => $val) {
         $queuecount += $val;
     }
     return $queuecount;
 }
示例#3
0
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  * @throws QueueAccessException
  */
 public function getNumberMessages($queueName, Priority $priority = null)
 {
     $nbrMsg = 0;
     if (null === $priority) {
         $priorities = $this->priorityHandler->getAll();
         foreach ($priorities as $priority) {
             $nbrMsg += $this->getNumberMessages($queueName, $priority);
         }
         return $nbrMsg;
     }
     if (empty($queueName)) {
         throw new \InvalidArgumentException('Queue name empty or not defined.');
     }
     try {
         $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl');
         $result = $this->sqsClient->getQueueAttributes(['QueueUrl' => $queueUrl, 'AttributeNames' => ['ApproximateNumberOfMessages']]);
     } catch (SqsException $e) {
         throw new QueueAccessException('Unable to get number of messages.', 0, $e);
     }
     $result = $result->get('Attributes');
     if (!empty($result['ApproximateNumberOfMessages']) && $result['ApproximateNumberOfMessages'] > 0) {
         return $result['ApproximateNumberOfMessages'];
     }
     return 0;
 }
示例#4
0
 public function getAttributes(array $attributeNames)
 {
     $args = ['QueueUrl' => $this->getQueueUrl()];
     if ($attributeNames) {
         /** @noinspection PhpUnusedLocalVariableInspection */
         foreach ($attributeNames as $name) {
             if (!in_array($name, self::ALL_ATTRIBUTES)) {
                 throw new \InvalidArgumentException("Unknown attribute {$name}");
             }
         }
         $args['AttributeNames'] = $attributeNames;
     } else {
         throw new \InvalidArgumentException("You must specify some attributes");
     }
     $result = $this->client->getQueueAttributes($args);
     return $result['Attributes'];
 }
示例#5
0
 /**
  * Get the size of the queue.
  *
  * @param  string  $queue
  * @return int
  */
 public function size($queue = null)
 {
     return (int) $this->sqs->getQueueAttributes(['QueueUrl' => $this->getQueue($queue)])->get('ApproximateNumberOfMessages');
 }
 public function getMessageCount($queueUrl)
 {
     $result = $this->service->getQueueAttributes(array('QueueUrl' => $queueUrl, 'AttributeNames' => array('ApproximateNumberOfMessages')));
     $messagesCount = $result->getPath('Attributes/ApproximateNumberOfMessages');
     return $messagesCount;
 }
示例#7
0
 /**
  * {@inheritDoc}
  */
 public function count()
 {
     $response = $this->client->getQueueAttributes(['QueueUrl' => $this->getUrl(), 'AttributeNames' => ['All']]);
     return (int) $response->getPath('Attributes/ApproximateNumberOfMessages');
 }