Skip to content

Commit

Permalink
Check queue name on message pick
Browse files Browse the repository at this point in the history
  • Loading branch information
renatocason committed Jul 20, 2018
1 parent bfbd8d8 commit dc3b64d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Api/QueueMessageRepositoryInterface.php
Expand Up @@ -22,9 +22,10 @@ public function create(QueueMessageInterface $message);
/**
* Take first element in the queue without removing it
*
* @param string $queueName
* @return \Rcason\MqMysql\Api\Data\QueueMessageInterface
*/
public function peek();
public function peek(string $queueName);

/**
* Get message by id
Expand Down
2 changes: 1 addition & 1 deletion Model/MysqlBroker.php
Expand Up @@ -67,7 +67,7 @@ public function enqueue(MessageEnvelopeInterface $messageEnvelope)
*/
public function peek()
{
$queueMessage = $this->queueMessageRepository->peek();
$queueMessage = $this->queueMessageRepository->peek($this->queueName);
if(!$queueMessage || !$queueMessage->getId()) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion Model/Queue/MessageRepository.php
Expand Up @@ -63,11 +63,12 @@ public function create(QueueMessageInterface $message)
/**
* @inheritdoc
*/
public function peek()
public function peek(string $queueName)
{
// Create collection instance and apply filter
$collection = $this->collectionFactory->create()
->addFieldToFilter('status', 0)
->addFieldToFilter('queue_name', $queueName)
->setOrder('updated_at', 'ASC')
->setCurPage(1)
->setPageSize(1);
Expand Down
3 changes: 2 additions & 1 deletion Test/Unit/Model/Queue/MessageRepositoryTest.php
Expand Up @@ -15,6 +15,7 @@

class MessageRepositoryTest extends \PHPUnit\Framework\TestCase
{
const QUEUE_NAME = 'test';
const MAX_RETRIES = 5;
const MESSAGE_ID = 7;

Expand Down Expand Up @@ -118,7 +119,7 @@ public function testPeek()
->willReturn($this->collection);

$this->assertEquals(
$this->messageRepository->peek(),
$this->messageRepository->peek(self::QUEUE_NAME),
$this->message
);
}
Expand Down

0 comments on commit dc3b64d

Please sign in to comment.