Skip to content

Commit

Permalink
Merge branch 'alexbumbacea-stop-restart-consumer'
Browse files Browse the repository at this point in the history
  • Loading branch information
skafandri committed Sep 3, 2016
2 parents a7e14d9 + 3b73bf1 commit 1e7bd58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions RabbitMq/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public function processMessage(AMQPMessage $msg)
'return_code' => $processFlag
)
));
} catch (Exception\StopConsumerException $e) {
$this->logger->info('Consumer requested restart', array(
'amqp' => array(
'queue' => $this->queueOptions['name'],
'message' => $msg,
'stacktrace' => $e->getTraceAsString()
)
));
$this->stopConsuming();
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), array(
'amqp' => array(
Expand Down
15 changes: 15 additions & 0 deletions RabbitMq/Exception/StopConsumerException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace OldSound\RabbitMqBundle\RabbitMq\Exception;

/**
* If this exception is thrown in consumer service the message
* will not be ack and consumer will stop
* if using demonized, ex: supervisor, the consumer will actually restart
* Class RestartConsumerException
* @package OldSound\RabbitMqBundle\RabbitMq\Exception
*/
class StopConsumerException extends \RuntimeException
{

}

0 comments on commit 1e7bd58

Please sign in to comment.