@@ -43,9 +43,11 @@ class AmqpContext implements InteropAmqpContext, DelayStrategyAware
43
43
private $ receiveMethod ;
44
44
45
45
/**
46
+ * an item contains an array: [AmqpConsumerInterop $consumer, callable $callback];.
47
+ *
46
48
* @var array
47
49
*/
48
- private $ basicConsumeSubscribers ;
50
+ private $ subscribers ;
49
51
50
52
/**
51
53
* Callable must return instance of \AMQPChannel once called.
@@ -66,7 +68,7 @@ public function __construct($extChannel, $receiveMethod)
66
68
}
67
69
68
70
$ this ->buffer = new Buffer ();
69
- $ this ->basicConsumeSubscribers = [];
71
+ $ this ->subscribers = [];
70
72
}
71
73
72
74
/**
@@ -298,23 +300,11 @@ public function getExtChannel()
298
300
}
299
301
300
302
/**
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}
314
304
*/
315
- public function basicConsumeSubscribe (InteropAmqpConsumer $ consumer , callable $ callback )
305
+ public function subscribe (InteropAmqpConsumer $ consumer , callable $ callback )
316
306
{
317
- if ($ consumer ->getConsumerTag () && array_key_exists ($ consumer ->getConsumerTag (), $ this ->basicConsumeSubscribers )) {
307
+ if ($ consumer ->getConsumerTag () && array_key_exists ($ consumer ->getConsumerTag (), $ this ->subscribers )) {
318
308
return ;
319
309
}
320
310
@@ -325,10 +315,13 @@ public function basicConsumeSubscribe(InteropAmqpConsumer $consumer, callable $c
325
315
326
316
$ consumerTag = $ extQueue ->getConsumerTag ();
327
317
$ consumer ->setConsumerTag ($ consumerTag );
328
- $ this ->basicConsumeSubscribers [$ consumerTag ] = [$ consumer , $ callback ];
318
+ $ this ->subscribers [$ consumerTag ] = [$ consumer , $ callback ];
329
319
}
330
320
331
- public function basicConsumeUnsubscribe (InteropAmqpConsumer $ consumer )
321
+ /**
322
+ * {@inheritdoc}
323
+ */
324
+ public function unsubscribe (InteropAmqpConsumer $ consumer )
332
325
{
333
326
if (false == $ consumer ->getConsumerTag ()) {
334
327
return ;
@@ -341,15 +334,15 @@ public function basicConsumeUnsubscribe(InteropAmqpConsumer $consumer)
341
334
$ extQueue ->setName ($ consumer ->getQueue ()->getQueueName ());
342
335
343
336
$ extQueue ->cancel ($ consumerTag );
344
- unset($ this ->basicConsumeSubscribers [$ consumerTag ]);
337
+ unset($ this ->subscribers [$ consumerTag ]);
345
338
}
346
339
347
340
/**
348
- * @param float|int $timeout milliseconds, consumes endlessly if zero set
341
+ * {@inheritdoc}
349
342
*/
350
- public function basicConsume ($ timeout = 0 )
343
+ public function consume ($ timeout = 0 )
351
344
{
352
- if (empty ($ this ->basicConsumeSubscribers )) {
345
+ if (empty ($ this ->subscribers )) {
353
346
throw new \LogicException ('There is no subscribers. Consider calling basicConsumeSubscribe before consuming ' );
354
347
}
355
348
@@ -360,9 +353,9 @@ public function basicConsume($timeout = 0)
360
353
try {
361
354
$ extConnection ->setReadTimeout ($ timeout / 1000 );
362
355
363
- reset ($ this ->basicConsumeSubscribers );
356
+ reset ($ this ->subscribers );
364
357
/** @var $consumer AmqpConsumer */
365
- list ($ consumer ) = current ($ this ->basicConsumeSubscribers );
358
+ list ($ consumer ) = current ($ this ->subscribers );
366
359
367
360
$ extQueue = new \AMQPQueue ($ this ->getExtChannel ());
368
361
$ extQueue ->setName ($ consumer ->getQueue ()->getQueueName ());
@@ -374,7 +367,7 @@ public function basicConsume($timeout = 0)
374
367
* @var AmqpConsumer
375
368
* @var callable $callback
376
369
*/
377
- list ($ consumer , $ callback ) = $ this ->basicConsumeSubscribers [$ q ->getConsumerTag ()];
370
+ list ($ consumer , $ callback ) = $ this ->subscribers [$ q ->getConsumerTag ()];
378
371
379
372
return call_user_func ($ callback , $ message , $ consumer );
380
373
}, AMQP_JUST_CONSUME );
0 commit comments