Skip to content

Commit 99be00e

Browse files
committed
Ability to restart consumer from within "execute" by throwing
\OldSound\RabbitMqBundle\RabbitMq\Exception\StopConsumerException
1 parent 4f8c356 commit 99be00e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

RabbitMq/Consumer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ public function processMessage(AMQPMessage $msg)
9090
'return_code' => $processFlag
9191
)
9292
));
93+
} catch (Exception\StopConsumerException $e) {
94+
$this->logger->info('Consumer requested restart', array(
95+
'amqp' => array(
96+
'queue' => $this->queueOptions['name'],
97+
'message' => $msg,
98+
'stacktrace' => $e->getTraceAsString()
99+
)
100+
));
101+
$this->stopConsuming();
93102
} catch (\Exception $e) {
94103
$this->logger->error($e->getMessage(), array(
95104
'amqp' => array(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\RabbitMq\Exception;
4+
5+
/**
6+
* If this exception is thrown in consumer service the message
7+
* will not be ack and consumer will stop
8+
* if using demonized, ex: supervisor, the consumer will actually restart
9+
* Class RestartConsumerException
10+
* @package OldSound\RabbitMqBundle\RabbitMq\Exception
11+
*/
12+
class StopConsumerException extends \RuntimeException
13+
{
14+
15+
}

0 commit comments

Comments
 (0)