diff --git a/src/Common/Internal/Resources.php b/src/Common/Internal/Resources.php index b9e674cb4..a9d133f67 100644 --- a/src/Common/Internal/Resources.php +++ b/src/Common/Internal/Resources.php @@ -408,7 +408,9 @@ class Resources { const LIST_RULES_PATH = '%s/subscriptions/%s/rules'; const LIST_SUBSCRIPTIONS_PATH = '%s/subscriptions'; const RECEIVE_MESSAGE_PATH = '%s/messages/head'; + const RECEIVE_MESSAGE_DEADLETTER_PATH = '%s/$DeadLetterQueue/messages/head'; const RECEIVE_SUBSCRIPTION_MESSAGE_PATH = '%s/subscriptions/%s/messages/head'; + const RECEIVE_SUBSCRIPTION_MESSAGE_DEADLETTER_PATH = '%s/subscriptions/%s/$DeadLetterQueue/messages/head'; const SEND_MESSAGE_PATH = '%s/messages'; const RULE_PATH = '%s/subscriptions/%s/rules/%s'; const SUBSCRIPTION_PATH = '%s/subscriptions/%s'; diff --git a/src/ServiceBus/Models/ReceiveMessageOptions.php b/src/ServiceBus/Models/ReceiveMessageOptions.php index ee30d105d..9297bf05a 100644 --- a/src/ServiceBus/Models/ReceiveMessageOptions.php +++ b/src/ServiceBus/Models/ReceiveMessageOptions.php @@ -53,6 +53,13 @@ class ReceiveMessageOptions */ private $_receiveMode; + /** + * Flag to receive from deadletter instead + * + * @var bool + */ + private $deadLetter = false; + /** * Creates a receive message option instance with default parameters. */ @@ -135,4 +142,22 @@ public function setPeekLock() { $this->_receiveMode = ReceiveMode::PEEK_LOCK; } + + /** + * Enable deadletter flag + */ + public function setDeadLetter() + { + $this->deadLetter = true; + } + + /** + * Get deadletter flag + * + * @return bool + */ + public function getDeadLetter() + { + return $this->deadLetter; + } } diff --git a/src/ServiceBus/ServiceBusRestProxy.php b/src/ServiceBus/ServiceBusRestProxy.php index 972e2ab04..c240041d3 100644 --- a/src/ServiceBus/ServiceBusRestProxy.php +++ b/src/ServiceBus/ServiceBusRestProxy.php @@ -166,7 +166,12 @@ public function receiveQueueMessage( $queueName, ReceiveMessageOptions $receiveMessageOptions = null ) { - $queueMessagePath = sprintf(Resources::RECEIVE_MESSAGE_PATH, $queueName); + $pathFormat = Resources::RECEIVE_MESSAGE_PATH; + if ($receiveMessageOptions->getDeadLetter()) { + $pathFormat = Resources::RECEIVE_MESSAGE_DEADLETTER_PATH; + } + + $queueMessagePath = sprintf($pathFormat, $queueName); return $this->receiveMessage( $queueMessagePath, @@ -300,8 +305,13 @@ public function receiveSubscriptionMessage( $subscriptionName, ReceiveMessageOptions $receiveMessageOptions = null ) { + $pathFormat = Resources::RECEIVE_SUBSCRIPTION_MESSAGE_PATH; + if ($receiveMessageOptions->getDeadLetter()) { + $pathFormat = Resources::RECEIVE_SUBSCRIPTION_MESSAGE_DEADLETTER_PATH; + } + $messagePath = sprintf( - Resources::RECEIVE_SUBSCRIPTION_MESSAGE_PATH, + $pathFormat, $topicName, $subscriptionName ); diff --git a/tests/unit/WindowsAzure/ServiceBus/models/ReceiveMessageOptionsTest.php b/tests/unit/WindowsAzure/ServiceBus/models/ReceiveMessageOptionsTest.php index 5ca640e4d..4ce3907cc 100644 --- a/tests/unit/WindowsAzure/ServiceBus/models/ReceiveMessageOptionsTest.php +++ b/tests/unit/WindowsAzure/ServiceBus/models/ReceiveMessageOptionsTest.php @@ -98,4 +98,32 @@ public function testGetSetReceiveMode() $actual ); } + + /** + * @covers \WindowsAzure\ServiceBus\Models\ReceiveMessageOptions::getDeadLetter + * @covers \WindowsAzure\ServiceBus\Models\ReceiveMessageOptions::setDeadLetter + */ + public function testGetSetDeadLetter() + { + // Setup + $receiveMessageOptions = new ReceiveMessageOptions(); + + // Test + $receiveMessageOptions->setDeadLetter(); + + // Assert + $this->assertTrue($receiveMessageOptions->getDeadLetter()); + } + + /** + * @covers \WindowsAzure\ServiceBus\Models\ReceiveMessageOptions::getDeadLetter + */ + public function testGetDeadLetterByDefault() + { + // Setup + $receiveMessageOptions = new ReceiveMessageOptions(); + + // Assert + $this->assertFalse($receiveMessageOptions->getDeadLetter()); + } }