예제 #1
0
 /**
  * @throws \PHPQueue\Exception\JobNotFoundException
  * @return array
  */
 public function get()
 {
     $this->beforeGet();
     $this->checkQueue();
     try {
         $options = new ReceiveMessageOptions();
         $options->setPeekLock();
         $response = $this->getConnection()->receiveQueueMessage($this->queue_name, $options);
         if (empty($response)) {
             throw new JobNotFoundException('No message found.', 404);
         }
         $this->last_job = $response;
         $this->last_job_id = $response->getMessageId();
         $this->afterGet();
         return json_decode($response->getBody(), TRUE);
     } catch (ServiceException $ex) {
         throw new JobNotFoundException($ex->getMessage(), $ex->getCode());
     }
 }
 /**
  * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::unlockMessage
  */
 public function testPeekLockedMessageCanBeUnlocked()
 {
     // Setup
     $queueDescription = new QueueDescription();
     $queueName = 'testPeekLockMessageCanBeUnlocked';
     $expectedMessage = 'testPeekLockMessageCanBeUnlocked';
     $queueInfo = new QueueInfo($queueName, $queueDescription);
     $this->safeDeleteQueue($queueName);
     $this->createQueue($queueInfo);
     $brokeredMessage = new BrokeredMessage();
     $brokeredMessage->setBody($expectedMessage);
     $this->restProxy->sendQueueMessage($queueName, $brokeredMessage);
     $receiveMessageOptions = new ReceiveMessageOptions();
     $receiveMessageOptions->setTimeout(5);
     $receiveMessageOptions->setPeekLock();
     $peekedMessage = $this->restProxy->receiveQueueMessage($queueName, $receiveMessageOptions);
     $lockToken = $peekedMessage->getLockToken();
     $lockedUntilUtc = $peekedMessage->getLockedUntilUtc();
     // Test
     $this->restProxy->unlockMessage($peekedMessage);
     $receiveMessageOptions->setReceiveAndDelete();
     $unlockedMessage = $this->restProxy->receiveQueueMessage($queueName, $receiveMessageOptions);
     // Assert
     $this->assertNotNull($lockToken);
     $this->assertNotNull($lockedUntilUtc);
     $this->assertNull($unlockedMessage->getLockToken());
     $this->assertNull($unlockedMessage->getLockedUntilUtc());
 }
 /**
  * Pop the next job off of the queue.
  *
  * @param  string $queue
  *
  * @return \Illuminate\Queue\Jobs\Job|null
  */
 public function pop($queue = null)
 {
     $queue = $this->getQueue($queue);
     $options = new ReceiveMessageOptions();
     $options->setPeekLock();
     $job = $this->azure->receiveQueueMessage($queue, $options);
     if (!is_null($job)) {
         return new AzureJob($this->container, $this->azure, $job, $queue);
     }
 }