/**
  * Push a new job onto the queue after a delay.
  *
  * @param  int    $delay
  * @param  string $job
  * @param  mixed  $data
  * @param  string $queue
  *
  * @return void
  */
 public function later($delay, $job, $data = '', $queue = null)
 {
     $payload = $this->createPayload($job, $data);
     $release = new \DateTime();
     $release->setTimezone(new \DateTimeZone('UTC'));
     $release->add(new \DateInterval('PT' . $delay . 'S'));
     $message = new BrokeredMessage($payload);
     $message->setScheduledEnqueueTimeUtc($release);
     $this->azure->sendQueueMessage($this->getQueue($queue), $message);
 }
Пример #2
0
 /**
  * @param  array                                $data
  * @throws \PHPQueue\Exception\BackendException
  * @return boolean                              Status of saving
  */
 public function add($data = array())
 {
     $this->beforeAdd();
     $this->checkQueue();
     try {
         $message = new BrokeredMessage();
         $message->setBody(json_encode($data));
         $this->getConnection()->sendQueueMessage($this->queue_name, $message);
     } catch (ServiceException $ex) {
         throw new BackendException($ex->getMessage(), $ex->getCode());
     }
     return true;
 }
 /**
  * Deletes a brokered message. 
  *
  * Queues:
  *
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780767
  * 
  * Topic Subscriptions:
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780768
  * 
  * @param BrokeredMessage $brokeredMessage The brokered message.
  *
  * @return none
  */
 public function deleteMessage($brokeredMessage)
 {
     $httpCallContext = new HttpCallContext();
     $httpCallContext->setMethod(Resources::HTTP_DELETE);
     $lockLocation = $brokeredMessage->getLockLocation();
     $lockLocationArray = parse_url($lockLocation);
     $lockLocationPath = Resources::EMPTY_STRING;
     if (array_key_exists(Resources::PHP_URL_PATH, $lockLocationArray)) {
         $lockLocationPath = $lockLocationArray[Resources::PHP_URL_PATH];
         $lockLocationPath = preg_replace('@^\\/@', Resources::EMPTY_STRING, $lockLocationPath);
     }
     if (empty($lockLocationPath)) {
         throw new \InvalidArgumentException(Resources::MISSING_LOCK_LOCATION_MSG);
     }
     $httpCallContext->setPath($lockLocationPath);
     $httpCallContext->addStatusCode(Resources::STATUS_OK);
     $this->sendContext($httpCallContext);
 }
 /** 
  * @covers WindowsAzure\ServiceBus\Models\BrokeredMessage::getLockLocation
  * @covers WindowsAzure\ServiceBus\Models\BrokeredMessage::setLockLocation
  */
 public function testGetSetLockLocation()
 {
     // Setup
     $expected = 'testLockLocation';
     $brokeredMessage = new BrokeredMessage();
     // Test
     $brokeredMessage->setLockLocation($expected);
     $actual = $brokeredMessage->getLockLocation();
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * Get the raw body string for the job.
  *
  * @return string
  */
 public function getRawBody()
 {
     return $this->job->getBody();
 }
 private function createIssueMessage($issueId, $issueBody, $label, $i)
 {
     $message = new BrokeredMessage($issueBody);
     $message->setContentType('text/xml');
     $message->setLabel($label);
     $message->setReplyTo('1@1.com');
     $message->setMessageId($issueId);
     $customProperties = $this->getCustomProperties($i);
     foreach ($customProperties as $key => $value) {
         $message->setProperty($key, $value);
     }
     return $message;
 }
 /**
  * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::receiveQueueMessage
  */
 public function testMessageMayHaveCustomProperties()
 {
     // Setup
     $queueName = 'testMessageMayHaveCustomProperties';
     $queueDescription = new QueueDescription();
     $queueInfo = new QueueInfo($queueName, $queueDescription);
     $expectedTestStringValue = 'testStringValue';
     $expectedTestIntValue = 38;
     $expectedTestDoubleValue = 3.14159;
     $expectedTestBooleanValue = true;
     $expectedTestBooleanFalseValue = false;
     $expectedTestArrayValue = array(2, 3, 5, 7);
     $this->safeDeleteQueue($queueName);
     $this->createQueue($queueInfo);
     $brokeredMessage = new BrokeredMessage();
     $brokeredMessage->setProperty('testString', $expectedTestStringValue);
     $brokeredMessage->setProperty('testInt', $expectedTestIntValue);
     $brokeredMessage->setProperty('testDouble', $expectedTestDoubleValue);
     $brokeredMessage->setProperty('testBoolean', $expectedTestBooleanValue);
     $brokeredMessage->setProperty('testBooleanFalse', $expectedTestBooleanFalseValue);
     $this->restProxy->sendQueueMessage($queueName, $brokeredMessage);
     $receiveMessageOptions = new ReceiveMessageOptions();
     $receiveMessageOptions->setTimeout(5);
     $receiveMessageOptions->setReceiveAndDelete();
     // Test
     $receivedMessage = $this->restProxy->receiveQueueMessage($queueName, $receiveMessageOptions);
     // Assert
     $this->assertNotNull($receivedMessage);
     $this->assertEquals($expectedTestStringValue, $receivedMessage->getProperty('testString'));
     $this->assertEquals($expectedTestIntValue, $receivedMessage->getProperty('testInt'));
     $this->assertEquals($expectedTestDoubleValue, $receivedMessage->getProperty('testDouble'));
     $this->assertEquals($expectedTestBooleanValue, $receivedMessage->getProperty('testBoolean'));
     $this->assertEquals($expectedTestBooleanFalseValue, $receivedMessage->getProperty('testBooleanFalse'));
 }
 private function createIssueMessage($issueId, $issueBody, $label, $messageLocation)
 {
     $message = new BrokeredMessage($issueBody);
     $bp = new BrokerProperties();
     $bp->setLabel($label);
     //        $bp->setMessageLocation($messageLocation);
     $bp->setReplyTo('test@test.com');
     $bp->setMessageId($issueId);
     $bp->setCorrelationId('correlationid' + $label);
     $bp->setDeliveryCount(1);
     $bp->setLockedUntilUtc(new \DateTime('2/4/1984'));
     $bp->setLockLocation($label + 'locallocation');
     $bp->setLockToken($label + 'locltoken');
     $bp->setSequenceNumber(12);
     $message->setBrokerProperties($bp);
     $message->setContentType('text/xml');
     $message->setLabel($label);
     $message->setReplyTo('1@1.com');
     $message->setMessageId($issueId);
     $customProperties = $this->getCustomProperties(1);
     foreach ($customProperties as $key => $value) {
         $message->setProperty($key, $value);
     }
     return $message;
 }
 /**
  * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createQueue
  * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::receiveQueueMessage
  * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::sendQueueMessage
  */
 public function testMessagesMayHaveCustomProperties()
 {
     // Arrange
     $queueName = 'TestMessagesMayHaveCustomProperties';
     $this->restProxy->createQueue(new QueueInfo($queueName));
     // Act
     $message = new BrokeredMessage('');
     $message->setProperty('hello', 'world');
     $message->setProperty('foo', 42);
     $this->restProxy->sendQueueMessage($queueName, $message);
     $message = $this->restProxy->receiveQueueMessage($queueName, $this->RECEIVE_AND_DELETE_5_SECONDS);
     // Assert
     $this->assertEquals('world', $message->getProperty('hello'), '$message->getProperty(\'hello\')');
     $this->assertEquals(42, $message->getProperty('foo'), '$message->getProperty(\'foo\')');
 }