Skip to content

Commit

Permalink
Merge pull request #12 from queue-interop/subscription-consumer
Browse files Browse the repository at this point in the history
Add subscription consumer interface
  • Loading branch information
makasim committed Aug 5, 2018
2 parents ad508a8 + 081f57c commit 950c808
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/PsrSubscriptionConsumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Interop\Queue;

interface PsrSubscriptionConsumer
{
/**
* @param float|int $timeout Milliseconds 1000 is 1 second, a zero is consume endlessly.
*/
public function consume($timeout = 0);

/**
* Notify broker that the client is interested in consuming messages from this queue.
*
* A callback function to which the consumed message will be passed.
* The function must accept at a minimum one parameter, an \Interop\Queue\PsrMessage object,
* and an optional second parameter the \Interop\Queue\PsrConsumer from which the message was
* consumed. The consumer will not return the processing thread back to
* the PHP script until the callback function returns FALSE.
*
* @param PsrConsumer $consumer
* @param callable $callback
*
* @return void
*/
public function subscribe(PsrConsumer $consumer, callable $callback);

/**
* @param PsrConsumer $consumer
*
* @return void
*/
public function unsubscribe(PsrConsumer $consumer);

/**
* Unsubscribe all subscribed consumers.
*
* @return void
*/
public function unsubscribeAll();
}
10 changes: 10 additions & 0 deletions src/PsrSubscriptionConsumerAwareContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Interop\Queue;

interface PsrSubscriptionConsumerAwareContext
{
/**
* @return PsrSubscriptionConsumer
*/
public function createSubscriptionConsumer();
}

0 comments on commit 950c808

Please sign in to comment.