コード例 #1
0
ファイル: SqsAdapterTest.php プロジェクト: graze/queue
 protected function stubCreateDequeueMessage($body, $id, $handle)
 {
     $this->factory->shouldReceive('createMessage')->once()->with($body, m::on(function ($opts) use($id, $handle) {
         $meta = ['Attributes' => [], 'MessageAttributes' => [], 'MessageId' => $id, 'ReceiptHandle' => $handle];
         $validator = isset($opts['validator']) && is_callable($opts['validator']);
         return isset($opts['metadata']) && $opts['metadata'] === $meta && $validator;
     }))->andReturn($this->messageA);
 }
コード例 #2
0
ファイル: SqsAdapter.php プロジェクト: traxo/queue
 /**
  * {@inheritdoc}
  *
  * @return Generator
  */
 public function dequeue(MessageFactoryInterface $factory, $limit)
 {
     $remaining = $limit ?: 0;
     while (null === $limit || $remaining > 0) {
         /**
          * If a limit has been specified, set {@see $size} so that we don't return more
          * than the requested number of messages if it's less than the batch size.
          */
         $size = $limit !== null ? min($remaining, self::BATCHSIZE_RECEIVE) : self::BATCHSIZE_RECEIVE;
         $timestamp = time() + $this->getQueueVisibilityTimeout();
         $validator = function () use($timestamp) {
             return time() < $timestamp;
         };
         $results = $this->client->receiveMessage(array_filter(['QueueUrl' => $this->getQueueUrl(), 'AttributeNames' => ['All'], 'MaxNumberOfMessages' => $size, 'VisibilityTimeout' => $this->getOption('VisibilityTimeout'), 'WaitTimeSeconds' => $this->getOption('ReceiveMessageWaitTimeSeconds')]));
         $messages = $results->get('Messages') ?: [];
         if (count($messages) === 0) {
             break;
         }
         foreach ($messages as $result) {
             (yield $factory->createMessage($result['Body'], ['metadata' => $this->createMessageMetadata($result), 'validator' => $validator]));
         }
         // Decrement the number of messages remaining.
         $remaining -= count($messages);
     }
 }