Skip to content

Commit

Permalink
Merge pull request #3 from robcaw/feature-max-priority
Browse files Browse the repository at this point in the history
Add max priority to queue
  • Loading branch information
rcwsr authored Sep 27, 2016
2 parents 66c1985 + 562453b commit b7e2517
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Broker/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Queue implements QueueInterface
*/
protected $deadLetterExchange;

/**
* @var int
*/
protected $maxPriority;

public function __construct(Connection $connection, $name, $durable = true, array $bindings)
{
$this->connection = $connection;
Expand Down Expand Up @@ -48,6 +53,16 @@ public function setDeadLetterExchange($deadLetterExchange)
$this->deadLetterExchange = $deadLetterExchange;
}

public function getMaxPriority()
{
return $this->maxPriority;
}

public function setMaxPriority($maxPriority)
{
$this->maxPriority = $maxPriority;
}

public function declareQueue()
{
$this->getAMQPQueue()->declareQueue();
Expand Down Expand Up @@ -105,6 +120,10 @@ private function getAMQPQueue()
if ($this->getDeadLetterExchange() !== null) {
$this->queue->setArgument('x-dead-letter-exchange', $this->getDeadLetterExchange());
}

if ($this->getMaxPriority() !== null) {
$this->queue->setArgument('x-max-priority', $this->getMaxPriority());
}
}

return $this->queue;
Expand Down
5 changes: 5 additions & 0 deletions src/Broker/QueueRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ private function create($name)
$queue->setDeadLetterExchange($config['dead_letter_exchange']);
}

// Set max priority
if (isset($config['max_priority'])) {
$queue->setMaxPriority($config['max_priority']);
}

return $queue;
}

Expand Down
60 changes: 60 additions & 0 deletions tests/Broker/QueueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Radish\Broker;

use AMQPQueue;
use Mockery;
use Mockery\Mock;
use PHPUnit_Framework_TestCase;

class QueueTest extends PHPUnit_Framework_TestCase
{
/**
* @var Queue
*/
private $queue;
/**
* @var Mock|Connection
*/
private $connection;
/**
* @var Mock|AMQPQueue
*/
private $amqpQueue;

public function setUp()
{
$this->amqpQueue = Mockery::mock('AMQPQueue', [
'declareQueue' => null,
'setName' => null,
'setFlags' => null,
]);

$this->connection = Mockery::mock('Radish\Broker\Connection', [
'createQueue' => $this->amqpQueue,
]);

$this->queue = new Queue($this->connection, 'test_queue', true, []);
}

public function testDeclareQueueSetsMaxPriorityArgOnAmqpQueue()
{
$this->queue->setMaxPriority(100);

$this->amqpQueue->shouldReceive('setArgument')
->with('x-max-priority', 100)
->once();

$this->queue->declareQueue();
}

public function testDeclareQueueDoesntSetMaxPriorityOnAmqpWhenNull()
{
$this->queue->setMaxPriority(null);

$this->amqpQueue->shouldReceive('setArgument')
->never();

$this->queue->declareQueue();
}
}

0 comments on commit b7e2517

Please sign in to comment.