@@ -43,9 +43,11 @@ class AmqpContext implements InteropAmqpContext, DelayStrategyAware
4343 private $ receiveMethod ;
4444
4545 /**
46+ * an item contains an array: [AmqpConsumerInterop $consumer, callable $callback];.
47+ *
4648 * @var array
4749 */
48- private $ basicConsumeSubscribers ;
50+ private $ subscribers ;
4951
5052 /**
5153 * Callable must return instance of \AMQPChannel once called.
@@ -66,7 +68,7 @@ public function __construct($extChannel, $receiveMethod)
6668 }
6769
6870 $ this ->buffer = new Buffer ();
69- $ this ->basicConsumeSubscribers = [];
71+ $ this ->subscribers = [];
7072 }
7173
7274 /**
@@ -298,23 +300,11 @@ public function getExtChannel()
298300 }
299301
300302 /**
301- * Notify broker that the channel is interested in consuming messages from this queue.
302- *
303- * @param InteropAmqpConsumer $consumer
304- * @param callable $callback A callback function to which the
305- * consumed message will be passed. The
306- * function must accept at a minimum
307- * one parameter, an \Interop\Amqp\AmqpMessage object,
308- * and an optional second parameter
309- * the \Interop\Amqp\AmqpConsumer from which the message was
310- * consumed. The \Interop\Amqp\AmqpContext::basicConsume() will
311- * not return the processing thread back to
312- * the PHP script until the callback
313- * function returns FALSE.
303+ * {@inheritdoc}
314304 */
315- public function basicConsumeSubscribe (InteropAmqpConsumer $ consumer , callable $ callback )
305+ public function subscribe (InteropAmqpConsumer $ consumer , callable $ callback )
316306 {
317- if ($ consumer ->getConsumerTag () && array_key_exists ($ consumer ->getConsumerTag (), $ this ->basicConsumeSubscribers )) {
307+ if ($ consumer ->getConsumerTag () && array_key_exists ($ consumer ->getConsumerTag (), $ this ->subscribers )) {
318308 return ;
319309 }
320310
@@ -325,10 +315,13 @@ public function basicConsumeSubscribe(InteropAmqpConsumer $consumer, callable $c
325315
326316 $ consumerTag = $ extQueue ->getConsumerTag ();
327317 $ consumer ->setConsumerTag ($ consumerTag );
328- $ this ->basicConsumeSubscribers [$ consumerTag ] = [$ consumer , $ callback ];
318+ $ this ->subscribers [$ consumerTag ] = [$ consumer , $ callback ];
329319 }
330320
331- public function basicConsumeUnsubscribe (InteropAmqpConsumer $ consumer )
321+ /**
322+ * {@inheritdoc}
323+ */
324+ public function unsubscribe (InteropAmqpConsumer $ consumer )
332325 {
333326 if (false == $ consumer ->getConsumerTag ()) {
334327 return ;
@@ -341,15 +334,15 @@ public function basicConsumeUnsubscribe(InteropAmqpConsumer $consumer)
341334 $ extQueue ->setName ($ consumer ->getQueue ()->getQueueName ());
342335
343336 $ extQueue ->cancel ($ consumerTag );
344- unset($ this ->basicConsumeSubscribers [$ consumerTag ]);
337+ unset($ this ->subscribers [$ consumerTag ]);
345338 }
346339
347340 /**
348- * @param float|int $timeout milliseconds, consumes endlessly if zero set
341+ * {@inheritdoc}
349342 */
350- public function basicConsume ($ timeout = 0 )
343+ public function consume ($ timeout = 0 )
351344 {
352- if (empty ($ this ->basicConsumeSubscribers )) {
345+ if (empty ($ this ->subscribers )) {
353346 throw new \LogicException ('There is no subscribers. Consider calling basicConsumeSubscribe before consuming ' );
354347 }
355348
@@ -360,9 +353,9 @@ public function basicConsume($timeout = 0)
360353 try {
361354 $ extConnection ->setReadTimeout ($ timeout / 1000 );
362355
363- reset ($ this ->basicConsumeSubscribers );
356+ reset ($ this ->subscribers );
364357 /** @var $consumer AmqpConsumer */
365- list ($ consumer ) = current ($ this ->basicConsumeSubscribers );
358+ list ($ consumer ) = current ($ this ->subscribers );
366359
367360 $ extQueue = new \AMQPQueue ($ this ->getExtChannel ());
368361 $ extQueue ->setName ($ consumer ->getQueue ()->getQueueName ());
@@ -374,7 +367,7 @@ public function basicConsume($timeout = 0)
374367 * @var AmqpConsumer
375368 * @var callable $callback
376369 */
377- list ($ consumer , $ callback ) = $ this ->basicConsumeSubscribers [$ q ->getConsumerTag ()];
370+ list ($ consumer , $ callback ) = $ this ->subscribers [$ q ->getConsumerTag ()];
378371
379372 return call_user_func ($ callback , $ message , $ consumer );
380373 }, AMQP_JUST_CONSUME );
0 commit comments