-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from php-enqueue/subscription-consumer
Improve multi queue consumption.
- Loading branch information
Showing
13 changed files
with
684 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Enqueue\AmqpTools; | ||
|
||
use Interop\Amqp\AmqpContext; | ||
use Interop\Queue\PsrConsumer; | ||
use Interop\Queue\PsrSubscriptionConsumer; | ||
|
||
/** | ||
* @deprecated this is BC layer, will be removed in 0.9 | ||
*/ | ||
final class SubscriptionConsumer implements PsrSubscriptionConsumer | ||
{ | ||
/** | ||
* @var AmqpContext | ||
*/ | ||
private $context; | ||
|
||
public function __construct(AmqpContext $context) | ||
{ | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function consume($timeout = 0) | ||
{ | ||
$this->context->consume($timeout); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function subscribe(PsrConsumer $consumer, callable $callback) | ||
{ | ||
$this->context->subscribe($consumer, $callback); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function unsubscribe(PsrConsumer $consumer) | ||
{ | ||
$this->context->unsubscribe($consumer); | ||
} | ||
|
||
/** | ||
* TODO. | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function unsubscribeAll() | ||
{ | ||
throw new \LogicException('Not implemented'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Enqueue\AmqpTools\Tests; | ||
|
||
use Enqueue\AmqpTools\SubscriptionConsumer; | ||
use Interop\Amqp\AmqpConsumer; | ||
use Interop\Amqp\AmqpContext; | ||
use Interop\Queue\PsrSubscriptionConsumer; | ||
|
||
class SubscriptionConsumerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testShouldImplementPsrSubscriptionConsumerInterface() | ||
{ | ||
$rc = new \ReflectionClass(SubscriptionConsumer::class); | ||
|
||
$this->assertTrue($rc->implementsInterface(PsrSubscriptionConsumer::class)); | ||
} | ||
|
||
public function testCouldBeConstructedWithAmqpContextAsFirstArgument() | ||
{ | ||
new SubscriptionConsumer($this->createContext()); | ||
} | ||
|
||
public function testShouldProxySubscribeCallToContextMethod() | ||
{ | ||
$consumer = $this->createConsumer(); | ||
$callback = function () {}; | ||
|
||
$context = $this->createContext(); | ||
$context | ||
->expects($this->once()) | ||
->method('subscribe') | ||
->with($this->identicalTo($consumer), $this->identicalTo($callback)) | ||
; | ||
|
||
$subscriptionConsumer = new SubscriptionConsumer($context); | ||
$subscriptionConsumer->subscribe($consumer, $callback); | ||
} | ||
|
||
public function testShouldProxyUnsubscribeCallToContextMethod() | ||
{ | ||
$consumer = $this->createConsumer(); | ||
|
||
$context = $this->createContext(); | ||
$context | ||
->expects($this->once()) | ||
->method('unsubscribe') | ||
->with($this->identicalTo($consumer)) | ||
; | ||
|
||
$subscriptionConsumer = new SubscriptionConsumer($context); | ||
$subscriptionConsumer->unsubscribe($consumer); | ||
} | ||
|
||
public function testShouldProxyConsumeCallToContextMethod() | ||
{ | ||
$timeout = 123.456; | ||
|
||
$context = $this->createContext(); | ||
$context | ||
->expects($this->once()) | ||
->method('consume') | ||
->with($this->identicalTo($timeout)) | ||
; | ||
|
||
$subscriptionConsumer = new SubscriptionConsumer($context); | ||
$subscriptionConsumer->consume($timeout); | ||
} | ||
|
||
public function testThrowsNotImplementedOnUnsubscribeAllCall() | ||
{ | ||
$context = $this->createContext(); | ||
|
||
$subscriptionConsumer = new SubscriptionConsumer($context); | ||
|
||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Not implemented'); | ||
$subscriptionConsumer->unsubscribeAll(); | ||
} | ||
|
||
/** | ||
* @return AmqpConsumer|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function createConsumer() | ||
{ | ||
return $this->createMock(AmqpConsumer::class); | ||
} | ||
|
||
/** | ||
* @return AmqpContext|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function createContext() | ||
{ | ||
return $this->createMock(AmqpContext::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.