public function testMissingDatesDeserializeAsNull() { // Act $properties = BrokerProperties::create('{}'); // Assert $this->assertNull($properties->getLockedUntilUtc(), '$properties->getLockedUntilUtc()'); $this->assertNull($properties->getScheduledEnqueueTimeUtc(), '$properties->getScheduledEnqueueTimeUtc()'); }
/** * Receives a message. * * Queues: * * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780735 * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780756 * * Topic Subscriptions: * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780722 * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780770 * * @param string $path The path of the * message. * @param ReceivedMessageOptions $receiveMessageOptions The options to * receive the message. * * @return BrokeredMessage */ public function receiveMessage($path, $receiveMessageOptions = null) { if (is_null($receiveMessageOptions)) { $receiveMessageOptions = new ReceiveMessageOptions(); } $httpCallContext = new HttpCallContext(); $httpCallContext->setPath($path); $httpCallContext->addStatusCode(Resources::STATUS_CREATED); $httpCallContext->addStatusCode(Resources::STATUS_NO_CONTENT); $httpCallContext->addStatusCode(Resources::STATUS_OK); $timeout = $receiveMessageOptions->getTimeout(); if (!is_null($timeout)) { $httpCallContext->addQueryParameter('timeout', $timeout); } if ($receiveMessageOptions->getIsReceiveAndDelete()) { $httpCallContext->setMethod(Resources::HTTP_DELETE); } elseif ($receiveMessageOptions->getIsPeekLock()) { $httpCallContext->setMethod(Resources::HTTP_POST); } else { throw new \InvalidArgumentException(Resources::INVALID_RECEIVE_MODE_MSG); } $response = $this->sendContext($httpCallContext); if ($response->getStatus() === Resources::STATUS_NO_CONTENT) { $brokeredMessage = null; } else { $responseHeaders = $response->getHeader(); $brokerProperties = new BrokerProperties(); if (array_key_exists('brokerproperties', $responseHeaders)) { $brokerProperties = BrokerProperties::create($responseHeaders['brokerproperties']); } if (array_key_exists('location', $responseHeaders)) { $brokerProperties->setLockLocation($responseHeaders['location']); } $brokeredMessage = new BrokeredMessage(); $brokeredMessage->setBrokerProperties($brokerProperties); if (array_key_exists(Resources::CONTENT_TYPE, $responseHeaders)) { $brokeredMessage->setContentType($responseHeaders[Resources::CONTENT_TYPE]); } if (array_key_exists('Date', $responseHeaders)) { $brokeredMessage->setDate($responseHeaders['Date']); } $brokeredMessage->setBody($response->getBody()); foreach (array_keys($responseHeaders) as $headerKey) { $value = $responseHeaders[$headerKey]; $decodedValue = json_decode($value); if (is_scalar($decodedValue)) { $brokeredMessage->setProperty($headerKey, $decodedValue); } } } return $brokeredMessage; }
/** * @covers WindowsAzure\ServiceBus\Models\BrokerProperties::getLockLocation * @covers WindowsAzure\ServiceBus\Models\BrokerProperties::setLockLocation */ public function testGetSetLockLocation() { // Setup $expected = 'testLockLocation'; $brokerProperties = new BrokerProperties(); // Test $brokerProperties->setLockLocation($expected); $actual = $brokerProperties->getLockLocation(); // Assert $this->assertEquals($expected, $actual); }
/** * Sets the location of the lock. * * @param string $lockLocation The location of the lock. * * @return none */ public function setLockLocation($lockLocation) { $this->_brokerProperties->setLockLocation($lockLocation); }
/** * Creates a broker properties instance with specified JSON message. * * @param string $brokerPropertiesJson A JSON message representing a * broker properties. * * @return none */ public static function create($brokerPropertiesJson) { Validate::isString($brokerPropertiesJson, 'brokerPropertiesJson'); $brokerProperties = new BrokerProperties(); $brokerPropertiesArray = (array) json_decode($brokerPropertiesJson); if (array_key_exists('CorrelationId', $brokerPropertiesArray)) { $brokerProperties->setCorrelationId($brokerPropertiesArray['CorrelationId']); } if (array_key_exists('SessionId', $brokerPropertiesArray)) { $brokerProperties->setSessionId($brokerPropertiesArray['SessionId']); } if (array_key_exists('DeliveryCount', $brokerPropertiesArray)) { $brokerProperties->setDeliveryCount($brokerPropertiesArray['DeliveryCount']); } if (array_key_exists('LockedUntilUtc', $brokerPropertiesArray)) { $brokerProperties->setLockedUntilUtc(\DateTime::createFromFormat(Resources::AZURE_DATE_FORMAT, $brokerPropertiesArray['LockedUntilUtc'])); } if (array_key_exists('LockToken', $brokerPropertiesArray)) { $brokerProperties->setLockToken($brokerPropertiesArray['LockToken']); } if (array_key_exists('MessageId', $brokerPropertiesArray)) { $brokerProperties->setMessageId($brokerPropertiesArray['MessageId']); } if (array_key_exists('Label', $brokerPropertiesArray)) { $brokerProperties->setLabel($brokerPropertiesArray['Label']); } if (array_key_exists('ReplyTo', $brokerPropertiesArray)) { $brokerProperties->setReplyTo($brokerPropertiesArray['ReplyTo']); } if (array_key_exists('SequenceNumber', $brokerPropertiesArray)) { $brokerProperties->setSequenceNumber($brokerPropertiesArray['SequenceNumber']); } if (array_key_exists('TimeToLive', $brokerPropertiesArray)) { $brokerProperties->setTimeToLive(doubleval($brokerPropertiesArray['TimeToLive'])); } if (array_key_exists('To', $brokerPropertiesArray)) { $brokerProperties->setTo($brokerPropertiesArray['To']); } if (array_key_exists('ScheduledEnqueueTimeUtc', $brokerPropertiesArray)) { $brokerProperties->setScheduledEnqueueTimeUtc(\DateTime::createFromFormat(Resources::AZURE_DATE_FORMAT, $brokerPropertiesArray['ScheduledEnqueueTimeUtc'])); } if (array_key_exists('ReplyToSessionId', $brokerPropertiesArray)) { $brokerProperties->setReplyToSessionId($brokerPropertiesArray['ReplyToSessionId']); } if (array_key_exists('MessageLocation', $brokerPropertiesArray)) { $brokerProperties->setMessageLocation($brokerPropertiesArray['MessageLocation']); } if (array_key_exists('LockLocation', $brokerPropertiesArray)) { $brokerProperties->setLockLocation($brokerPropertiesArray['LockLocation']); } return $brokerProperties; }
private function createIssueMessage($issueId, $issueBody, $label, $messageLocation) { $message = new BrokeredMessage($issueBody); $bp = new BrokerProperties(); $bp->setLabel($label); // $bp->setMessageLocation($messageLocation); $bp->setReplyTo('*****@*****.**'); $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('*****@*****.**'); $message->setMessageId($issueId); $customProperties = $this->getCustomProperties(1); foreach ($customProperties as $key => $value) { $message->setProperty($key, $value); } return $message; }