forked from php-amqplib/RabbitMqBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsumer.php
36 lines (29 loc) · 947 Bytes
/
Consumer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace OldSound\RabbitMqBundle\RabbitMq;
use OldSound\RabbitMqBundle\RabbitMq\BaseConsumer;
use PhpAmqpLib\Message\AMQPMessage;
class Consumer extends BaseConsumer
{
public function consume($msgAmount)
{
$this->target = $msgAmount;
$this->setUpConsumer();
while (count($this->ch->callbacks))
{
$this->ch->wait();
}
}
public function processMessage(AMQPMessage $msg)
{
if (false === call_user_func($this->callback, $msg)) {
// Reject and requeue message to RabbitMQ
$msg->delivery_info['channel']->basic_reject($msg->delivery_info['delivery_tag'], true);
}
else {
// Remove message from queue only if callback return not false
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
}
$this->consumed++;
$this->maybeStopConsumer();
}
}