Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscription consumer interface #12

Merged
merged 1 commit into from
Aug 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}